Removing all entities causes RuntimeError when an entity has a reference property

I created a button within my Cesium application that will delete all entities that are currently active. This is done on-click by looping through all DataSources in the viewer and calling the function DataSources.get(i).entities.removeAll(); where i is just an integer to grab a single data source out of the array. Everything works nicely until an entity with a reference property is added.

When an entity that has a reference property, for example a polyline with a positions referenced to a stationary ellipsoid and a moving billboard. When the button is pressed it throws an uncaught exception: RuntimeError: target entity “sat” could not be resolved. In this case “sat” is just the object id of one of the references. It seems like what’s happening is the removeAll() function deletes the two referenced entities before the polyline, so it throws an error because the polyline’s reference objects no longer exist. I’ll include the full console log below.

Is there a better way to remove the all entities that would avoid this, or possibly a way to pause updating entity properties until after the removeAll() loop is completed?

uncaught exception: RuntimeError: target entity “sat” could not be resolved.
RuntimeError@http://localhost:8080/Source/Core/RuntimeError.js:42:19
resolve@http://localhost:8080/Source/DataSources/ReferenceProperty.js:28:1
.isConstant.get@http://localhost:8080/Source/DataSources/ReferenceProperty.js:130:44
Property.isConstant@http://localhost:8080/Source/DataSources/Property.js:107:17
.isConstant.get@http://localhost:8080/Source/DataSources/PositionPropertyArray.js:57:26
PolylineGeometryUpdater.prototype._onEntityPropertyChanged@http://localhost:8080/Source/DataSources/PolylineGeometryUpdater.js:373:13
Event.prototype.raiseEvent@http://localhost:8080/Source/Core/Event.js:146:17
createProperty/<.set/this[subscriptionName]<@http://localhost:8080/Source/DataSources/createPropertyDescriptor.js:29:25
Event.prototype.raiseEvent@http://localhost:8080/Source/Core/Event.js:146:17
createProperty/<.set/this[subscriptionName]<@http://localhost:8080/Source/DataSources/createPropertyDescriptor.js:29:25
Event.prototype.raiseEvent@http://localhost:8080/Source/Core/Event.js:146:17
PositionPropertyArray.prototype._raiseDefinitionChanged@http://localhost:8080/Source/DataSources/PositionPropertyArray.js:184:9
Event.prototype.raiseEvent@http://localhost:8080/Source/Core/Event.js:146:17
ReferenceProperty.prototype._onCollectionChanged@http://localhost:8080/Source/DataSources/ReferenceProperty.js:336:17
Event.prototype.raiseEvent@http://localhost:8080/Source/Core/Event.js:146:17
fireChangedEvent@http://localhost:8080/Source/DataSources/EntityCollection.js:34:17
EntityCollection.prototype.resumeEvents@http://localhost:8080/Source/DataSources/EntityCollection.js:86:9
removeAllObjects@http://localhost:8080/Apps/CesiumViewer/CesiumViewer.js:401:13

``

Thanks,

Chris

We had issues like this at one time but I thought I took care of them all. Are you using the latest version of Cesium?

If so, can you try calling entities.suspendEvents() before the remove (followed by entities.resumeEvents() when you’re done).

If you’re still having a problem; can you post a small example to reproduce it?

Thanks

You’re right, I am on version 1.1 because I’m using the sensors plugin and had issues trying to update. I found your pull request and it looks like the fix went in for the 1.3 release. Thanks for your help.