Errors when changing the datasources of Viewer with InfoBox open

Hi ~ guys,

Yesterday, I updated Cesium from V1.4 to V1.9, there a some abnormal things occurred.

In my project, there is a group of radio selectors for user to choosing geojson data file and loading it into cesium.

When user click the loaded data, cesium’s InfoBox widget will popup and show some details of selected entity.

The abnormal scenario is : I always get a exception when I load a new geojson data with InfoBox open.

If I close the InfoBox widget, the data source changing operation is doing well.

The exception threw out as below:

An error occurred while rendering. Rendering has stopped.

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

Error

at new DeveloperError (http://192.168.0.1/test/Source/Core/DeveloperError.js:43:19)

at throwOnDestroyed (http://192.168.0.1/test/Source/Core/destroyObject.js:44:19)

at Batch.getBoundingSphere (http://192.168.0.1/test/Source/DataSources/StaticGeometryColorBatch.js:173:36)

at StaticGeometryColorBatch.getBoundingSphere (http://192.168.0.1/test/Source/DataSources/StaticGeometryColorBatch.js:266:43)

at GeometryVisualizer.getBoundingSphere (http://192.168.0.1/test/Source/DataSources/GeometryVisualizer.js:268:32)

at DataSourceDisplay.getBoundingSphere (http://192.168.0.1/test/Source/DataSources/DataSourceDisplay.js:311:40)

at Viewer._onTick (http://192.168.0.1/test/Source/Widgets/Viewer/Viewer.js:1299:49)

at Event.raiseEvent (http://192.168.0.1/test/Source/Core/Event.js:146:30)

at Clock.tick (http://192.168.0.1/test/Source/Core/Clock.js:203:21)

at CesiumWidget.render (http://192.168.0.1/test/Source/Widgets/CesiumWidget/CesiumWidget.js:649:43)

Thanks a lot for your help !!

Is it possible to demonstrate this error in the Sandcastle?

When writing the code in Sandcastle, I found maybe I should call the viewer.dataSources.removeAll() function before load next geojson data, other than call the viewer.dataSources.remove(dataSource, destroy) function.

After I have tried the above, the problem is solved.

So, I try to do some tests for the viewer.dataSources.remove() function as below in Sandcastle :

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

var ds = null;

Sandcastle.addToolbarButton(‘add foo’, function() {

loadData(’…/…/SampleData/ne_10m_us_states.topojson’, {

fill: Cesium.Color.PINK,

strokeWidth: 3

});

});

Sandcastle.addToolbarButton(‘add bar’, function() {

loadData(’…/…/SampleData/ne_10m_us_states.topojson’, {

fill: Cesium.Color.RED,

strokeWidth: 3

});

});

function loadData(url, style) {

if(ds != null) {

viewer.dataSources.remove(ds, true);

}

//viewer.dataSources.removeAll();

ds = Cesium.GeoJsonDataSource.load(url, style);

viewer.dataSources.add(ds);

}

The test result show that viewer.dataSource.remove(ds, true) always failed and return false.

Maybe there are some mistakes in my code.

It’s very kind of you if you can point it out to me.

Thanks !

Cesium.GeoJsonDataSource.load(url, style)
    .then(function (data) {
        dataSource = data;
        viewer.dataSources.add(dataSource);
    });

``

GeoJsonDataSource.load returns a Promise, not the resolved dataSource itself.

viewer.dataSources.add(…) accepts either a Promise or a dataSource object so it was able to resolve the dataSource from the Promise.