cleanup problem involving shadow node Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

cleanup problem involving shadow node

Post 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.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: cleanup problem involving shadow node

Post 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.
jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: cleanup problem involving shadow node

Post by jwwalker »

Thanks very much, that makes sense.