Page 1 of 1

cleanup problem involving shadow node

Posted: Wed Nov 03, 2021 12:51 am
by jwwalker
I'm trying to design a multi-document Mac application. I'm guessing that there should be one instance of Root, and maybe OverlaySystem, but that most other things should be per-document: Window, Camera, CompositorWorkspace, SceneManager. So when the document goes away, I want to clean up all the per-document data:

Code: Select all

_ogreSceneManager->destroyCamera( _ogreCamera );
Ogre::Root::getSingleton().destroySceneManager( _ogreSceneManager );
Ogre::Root::getSingleton().getCompositorManager2()->removeWorkspace( _ogreWorkspace );
Ogre::Root::getSingleton().getRenderSystem()->destroyRenderWindow( _ogreWindow );
The problem is that when I remove the workspace, I get a fatal exception, with the backtrace:

Code: Select all

void Ogre::SceneManager::checkMovableObjectIntegrity<Ogre::Camera>
Ogre::SceneManager::destroyCamera
Ogre::CompositorShadowNode::~CompositorShadowNode
Ogre::CompositorWorkspace::destroyAllNodes
Ogre::CompositorWorkspace::~CompositorWorkspace
Ogre::CompositorManager2::removeWorkspace
Do I need to do something more to clean up a shadow node? I had tried to imitate Sample_ShadowMapFromCode, and I must admit to a pretty darn fuzzy understanding of how compositors and shadow nodes work. It looks like there is a very loose connection between a shadow node and a CompositorWorkspace, and I don't see any public API methods in CompositorWorkspace having to do with removing or destroying a shadow node.

Re: cleanup problem involving shadow node

Posted: Wed Nov 03, 2021 2:05 am
by dark_sylinc
Remove the workspace before the scene manager.

The shadow node needs to create a few cameras (one for each shadow map); thus when you destroy the SceneManager first, the shadow node tries to use destroy its Camera via the SceneManager but everything is dangling pointers now.

Edit: In general follow LIFO order. If the workspace asked for a SceneManager when you were creating it; that means the SceneManager had to be created first. In turn, the SceneManager needs to be destroyed after the Workspace, not earlier.

Re: cleanup problem involving shadow node

Posted: Wed Nov 03, 2021 6:03 pm
by jwwalker
Thanks very much, that makes sense.