From 2f26fc11881bc4853817d06af6d22c81907bf64a Mon Sep 17 00:00:00 2001 From: cc9cii Date: Thu, 23 Oct 2014 20:14:01 +1100 Subject: [PATCH] Avoid Ogre exceptions and null pointers. --- apps/opencs/view/world/physicssystem.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index eeedfbb00..331625c84 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -170,12 +170,15 @@ namespace CSVWorld mSelectedEntities.find(result.first); if(iter != mSelectedEntities.end()) // currently selected { - std::vector deletedEntities = mSelectedEntities[result.first]; - while(!deletedEntities.empty()) + std::vector clonedEntities = mSelectedEntities[result.first]; + while(!clonedEntities.empty()) { - scene->detachObject(deletedEntities.back()); - mSceneMgr->destroyEntity(deletedEntities.back()); - deletedEntities.pop_back(); + if(mSceneMgr->hasEntity(clonedEntities.back())) + { + scene->detachObject(clonedEntities.back()); + mSceneMgr->destroyEntity(clonedEntities.back()); + } + clonedEntities.pop_back(); } mSelectedEntities.erase(iter); @@ -189,6 +192,9 @@ namespace CSVWorld while(iter.hasMoreElements()) { Ogre::MovableObject * element = iter.getNext(); + if(!element) + break; + if(element->getMovableType() != "Entity") continue;