How to remove primitives from a collection (or the collection itself) without developer error exception

1. A concise explanation of the problem you’re experiencing.

In spite of online searches and the apparently easy ‘emptying a collection’ task, I don’t know how to remove (and destroy at the same time) all primitives from a primitive collection or remove the collection itself from the scene.

Using the collection#remove() or collection#removeAll() methods both fail with “Uncaught DeveloperError: This object was destroyed, i.e., destroy() was called.”

A Sandcastle-ready code example follows.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var scene = viewer.scene;

var polyline;

var material = Cesium.Material.fromType(‘PolylineArrow’);

material.uniforms.color = new Cesium.Color(0,1.0,0,1.0);

var polylines = scene.primitives.add(new Cesium.PolylineCollection());

polyline = polylines.add({

positions : Cesium.PolylinePipeline.generateCartesianArc({

positions : Cesium.Cartesian3.fromDegreesArray([-110.0, 42.0,

-77.0, 12.0])

}),

width : 10.0,

show : true,

material: material

});

polylines.add({

positions : Cesium.PolylinePipeline.generateCartesianArc({

positions : Cesium.Cartesian3.fromDegreesArray([-120.0, 42.0,

-77.0, 12.0])

}),

width : 10.0,

show : true,

material: material

});

// Both the following ways fail to remove all the primitives,

// how to do it properly?

//setTimeout(()=> { scene.primitives.remove(polylines); },2000 );

setTimeout(()=> { polylines.removeAll(); },2000 );

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I need to remove and destroy all polyline primitive I previously created to replace them with freshly created others.

4. The Cesium version you’re using, your operating system and browser.

Cesium 1.59, Win 10 64Bit, Chrome 75.0.3770.100 64 bitt official build

TIA

Bump

Looks like this is a known bug, and it happens specifically because the polylines share a material, see: https://github.com/AnalyticalGraphicsInc/cesium/issues/1567

The suggested fix is to have a material per polyline.

Thanks Omar, any chance that bug will be fixed? (I have many primitives and a shared material would be the right way to go)