Possible bug in DataSourceCollection.remove

Hello everybody,

Please run the following script in the Sandcastle (Cesium 1.26):

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var options = {
camera : viewer.scene.camera,
canvas : viewer.scene.canvas
};
var kml = ‘…/…/SampleData/kml/facilities/facilities.kml’;
var ds;

Sandcastle.addToolbarMenu([{
text : ‘Load’,
onselect : function() {
//viewer.camera.flyHome(0);
ds = new Cesium.KmlDataSource(options);
ds.load(kml, options).then(function() {
console.log(‘loaded’ + ds.entities.values.length + ’ entities’);
});
}
}, {
text : ‘Add to viewer’,
onselect : function() {
viewer.dataSources.add(ds).then(function() {
console.log(‘added’);
});
}
},
{
text: ‘Remove from viewer’,
onselect: function() {
viewer.dataSources.remove(ds);
console.log(‘removed’);
}
}
], ‘toolbar’);

Sandcastle.reset = function() {
};

  1. Wait for “loaded” message in the console.
  2. Select “Add” in the toolbar menu. Wait for “added” message.
  3. Select “Remove” in the toolbar menu. Wait for “removed” message.
  4. Select “Add” again. The message “added” appears but the renderer crashes:
    An error occurred while rendering. Rendering has stopped.

undefined

TypeError: Unable to set property ‘id’ of undefined or null reference

TypeError: Unable to set property ‘id’ of undefined or null reference

at BillboardVisualizer.prototype.update (http://cesiumjs.org/Cesium/Source/DataSources/BillboardVisualizer.js:145:17)

at DataSourceDisplay.prototype.update (http://cesiumjs.org/Cesium/Source/DataSources/DataSourceDisplay.js:262:17)

at Viewer.prototype._onTick (http://cesiumjs.org/Cesium/Source/Widgets/Viewer/Viewer.js:1478:9)

at Event.prototype.raiseEvent (http://cesiumjs.org/Cesium/Source/Core/Event.js:147:17)
at Clock.prototype.tick (http://cesiumjs.org/Cesium/Source/Core/Clock.js:309:9)

at CesiumWidget.prototype.render (http://cesiumjs.org/Cesium/Source/Widgets/CesiumWidget/CesiumWidget.js:682:13)

at render (http://cesiumjs.org/Cesium/Source/Widgets/CesiumWidget/CesiumWidget.js:72:25)

I’ve always thought that DataSource should be still usable after removing from viewer.dataSources. Is this wrong?

By the way, Cesium.KmlDataSource constructor needs one argument, the documentation must be incorrect.

Thanks, Boris.

Thanks Boris! Based on the documentation and the code, I couldn’t find a good reason why you wouldn’t be able to do this. I filed a bug report on our GitHub so we can look into it: https://github.com/AnalyticalGraphicsInc/cesium/issues/4409

Best,

Hannah