How to destroy a model with out crashing

Hello. I built an application using Resium which uses several models, tilesets, polyline and polygons.
All are components under the Viewer component. What is the right way to exit from the whole Cesium component?
When i try to destroy the models i get this error that crashes my app:

An error occurred while rendering. Rendering has stopped.
DeveloperError: This object was destroyed, i.e., destroy() was called.
Error
at new DeveloperError (http://localhost:3000/cesium/Cesium.js:82:23)
at Model.throwOnDestroyed (http://localhost:3000/cesium/Cesium.js:29066:23)
at PrimitiveCollection.update (http://localhost:3000/cesium/Cesium.js:131116:31)
at updateAndRenderPrimitives (http://localhost:3000/cesium/Cesium.js:237416:31)
at executeCommandsInViewport (http://localhost:3000/cesium/Cesium.js:237250:17)
at Scene.updateAndExecuteCommands (http://localhost:3000/cesium/Cesium.js:237058:17)
at render (http://localhost:3000/cesium/Cesium.js:237721:19)
at tryAndCatchError (http://localhost:3000/cesium/Cesium.js:237740:17)
at Scene.render (http://localhost:3000/cesium/Cesium.js:237815:17)
at CesiumWidget.render (http://localhost:3000/cesium/Cesium.js:250280:29)

Thank you very much

This sounds like you’re possibly destroying the same model twice. I would double check if what you’re destroying has already been destroyed and/or run the browser debugger to see what leads to this error being thrown.

Im using one React component that includes inside 2 model components from Resium. They both share the same model Url. Do you think That might have something to do with this?
Thanks alot

There’s a good chance this is cause by this bug that has been around for 4+ years.

This is another bug report that has been open for 3+ years and I believe is caused by the same problematic code.

1 Like

And your fix was just merged, nice!