DeveloperError: A little help please!

I’m getting an error that says : uncaught exception: DeveloperError: This object was destroyed, i.e., destroy() was called.
@http://localhost:8080/Source/Core/DeveloperError.js:44.

In
my code I am adding/deleting point billboards and adding/deleting czml files. I can add points and czml files. The error happens when I delete point billboard points and the try to re-add czml files. The code for my
delete billboard points looks like:

function cleanup() {
widget.scene.getPrimitives().removeAll();
}

new Button({
label : ‘Delete point billboards’,
onClick : function() {
cleanup();
Sandcastle.highlight(addPointBillboards);
}
}).placeAt(‘toolbar’)

I
think the problem is with the getPrimitives.removeAll in the cleanup() function but I don’t know how to fix it. Any advice? Thanks

Can you post more of the error stack trace? That will help track down what code is using the destroyed objects. My suspicion is that it’s Sandcastle.highlight(addPointBillboards), which you should remove (you can’t highlight the billboards after they’ve been removed).

uncaught exception: DeveloperError: This object was destroyed, i.e., destroy() was called.

@http://localhost:8080/Source/Core/DeveloperError.js:44
throwOnDestroyed@http://localhost:8080/Source/Core/destroyObject.js:44

@http://localhost:8080/Source/DynamicScene/DynamicPolylineVisualizer.js:115
@http://localhost:8080/Source/DynamicScene/VisualizerCollection.js:129

@http://localhost:8080/Source/Widgets/Dojo/CesiumViewerWidget.js:533
czmlSensors
@http://localhost:8080/Apps/Sandcastle/templates/bucket.html:71
@http://localhost:8080/Apps/Sandcastle/templates/bucket.html:141
@http://localhost:8080/ThirdParty/dojo-release-1.8.3-src/dijit/form/_ButtonMixin.js:43
inherited
@http://localhost:8080/ThirdParty/dojo-release-1.8.3-src/dojo/_base/declare.js:189
@http://localhost:8080/ThirdParty/dojo-release-1.8.3-src/dijit/form/Button.js:64
@http://localhost:8080/ThirdParty/dojo-release-1.8.3-src/dojo/_base/lang.js:373

@http://localhost:8080/ThirdParty/dojo-release-1.8.3-src/dijit/a11yclick.js:84
(on line 0)

OK, I think I see the problem. The visualizers create primitives themselves in the scene based on the CZML data, so you need to be careful not to interfere with those primitives when you’re removing the point billboards that you are adding yourself.

Instead of calling removeAll(), you need to use remove() instead, passing in the BillboardCollection that you created to hold the point billboards. If your code is based on the Billboards Sandcastle example, you may have to rearrange the code so that the BillboardCollection instance is accessible from your cleanup function.