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

**URL:** <https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491>\
**Category:** CesiumJS\
**Created:** [July 25, 2019, 3:22pm UTC](https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491 "2019-07-25T15:22:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xllc](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xllc](https://community.cesium.com/u/xllc)\
**Post date:** [July 25, 2019, 3:22pm UTC](https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491/1 "2019-07-25T15:22:12Z")

</div>

**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

---

<div class="post-metadata">

**Author:** ![xygig](https://avatars.discourse-cdn.com/v4/letter/x/65b543/32.png) [@xygig](https://community.cesium.com/u/xygig)\
**Post date:** [August 8, 2019, 10:46am UTC](https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491/2 "2019-08-08T10:46:08Z")

</div>

Bump

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [August 9, 2019, 1:38pm UTC](https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491/3 "2019-08-09T13:38:44Z")

</div>

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](https://github.com/AnalyticalGraphicsInc/cesium/issues/1567)

The suggested fix is to have a material per polyline.

---

<div class="post-metadata">

**Author:** ![xygig](https://avatars.discourse-cdn.com/v4/letter/x/65b543/32.png) [@xygig](https://community.cesium.com/u/xygig)\
**Post date:** [August 11, 2019, 10:02pm UTC](https://community.cesium.com/t/how-to-remove-primitives-from-a-collection-or-the-collection-itself-without-developer-error-exception/8491/4 "2019-08-11T22:02:21Z")

</div>

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