diff --git a/apps/openmw/mwmechanics/objects.cpp b/apps/openmw/mwmechanics/objects.cpp index 45760b68b6..deebd8b39e 100644 --- a/apps/openmw/mwmechanics/objects.cpp +++ b/apps/openmw/mwmechanics/objects.cpp @@ -17,14 +17,17 @@ Objects::Objects() void Objects::addObject(const MWWorld::Ptr& ptr) { MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr); - if(anim) mObjects.insert(std::make_pair(ptr, CharacterController(ptr, anim))); + if(anim) mObjects.insert(std::make_pair(ptr, new CharacterController(ptr, anim))); } void Objects::removeObject(const MWWorld::Ptr& ptr) { PtrControllerMap::iterator iter = mObjects.find(ptr); if(iter != mObjects.end()) + { + delete iter->second; mObjects.erase(iter); + } } void Objects::updateObject(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr) @@ -32,10 +35,10 @@ void Objects::updateObject(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr) PtrControllerMap::iterator iter = mObjects.find(old); if(iter != mObjects.end()) { - CharacterController ctrl = iter->second; + CharacterController *ctrl = iter->second; mObjects.erase(iter); - ctrl.updatePtr(ptr); + ctrl->updatePtr(ptr); mObjects.insert(std::make_pair(ptr, ctrl)); } } @@ -46,7 +49,10 @@ void Objects::dropObjects (const MWWorld::Ptr::CellStore *cellStore) while(iter != mObjects.end()) { if(iter->first.getCell()==cellStore) + { + delete iter->second; mObjects.erase(iter++); + } else ++iter; } @@ -59,7 +65,7 @@ void Objects::update(float duration, bool paused) for(PtrControllerMap::iterator iter(mObjects.begin());iter != mObjects.end();++iter) { Movement movement; - iter->second.update(duration, movement); + iter->second->update(duration, movement); } } } @@ -68,13 +74,13 @@ void Objects::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& gro { PtrControllerMap::iterator iter = mObjects.find(ptr); if(iter != mObjects.end()) - iter->second.playGroup(groupName, mode, number); + iter->second->playGroup(groupName, mode, number); } void Objects::skipAnimation(const MWWorld::Ptr& ptr) { PtrControllerMap::iterator iter = mObjects.find(ptr); if(iter != mObjects.end()) - iter->second.skipAnim(); + iter->second->skipAnim(); } } diff --git a/apps/openmw/mwmechanics/objects.hpp b/apps/openmw/mwmechanics/objects.hpp index 7b1185a29a..5cdcdaa0af 100644 --- a/apps/openmw/mwmechanics/objects.hpp +++ b/apps/openmw/mwmechanics/objects.hpp @@ -16,7 +16,7 @@ namespace MWMechanics { class Objects { - typedef std::map PtrControllerMap; + typedef std::map PtrControllerMap; PtrControllerMap mObjects; public: