From c7fb27e801cca9d4d24ad912afc3d2a354ee437e Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 23 May 2011 20:22:12 +0200 Subject: [PATCH] Clean up wasn't done properly when deleting a Cell. --- apps/openmw/mwrender/exterior.cpp | 29 +++++++++++++++++++++++++++++ apps/openmw/mwrender/exterior.hpp | 2 ++ 2 files changed, 31 insertions(+) diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 3a17357bdd..8f3bccdb53 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -224,6 +224,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) { sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); + mScene.getMgr()->destroyEntity(ent); } if (mInsertMesh.empty()) mInsertMesh = mesh; @@ -363,10 +364,38 @@ void ExteriorCellRender::hide() mBase->setVisible(false); } +void ExteriorCellRender::destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode) +{ + if ( !i_pSceneNode ) + { + assert( false ); + return; + } + + // Destroy all the attached objects + SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator(); + + while ( itObject.hasMoreElements() ) + { + MovableObject* pObject = static_cast(itObject.getNext()); + i_pSceneNode->getCreator()->destroyMovableObject( pObject ); + } + + // Recurse to child SceneNodes + SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator(); + + while ( itChild.hasMoreElements() ) + { + SceneNode* pChildNode = static_cast(itChild.getNext()); + destroyAllAttachedMovableObjects( pChildNode ); + } +} + void ExteriorCellRender::destroy() { if(mBase) { + destroyAllAttachedMovableObjects(mBase); mBase->removeAndDestroyAllChildren(); mScene.getMgr()->destroySceneNode(mBase); } diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 4de421f445..40d9c60aec 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -125,6 +125,8 @@ namespace MWRender /// Remove the reference with the given handle permanently from the scene. virtual void deleteObject (const std::string& handle); + void destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode); + static int uniqueID; }; }