From a7d49285930df7b19242e7f8e0dab336812e4c32 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 18 Oct 2016 23:51:45 +0200 Subject: [PATCH] Properly handle moved references in respawning code (Fixes #3600) --- apps/openmw/mwworld/cellstore.cpp | 16 ++++++++++++---- apps/openmw/mwworld/cellstore.hpp | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index db3707441b..5e65bad7cb 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -204,6 +204,14 @@ namespace MWWorld return (ref.mRef.mRefnum == pRefnum); } + Ptr CellStore::getCurrentPtr(LiveCellRefBase *ref) + { + MovedRefTracker::iterator found = mMovedToAnotherCell.find(ref); + if (found != mMovedToAnotherCell.end()) + return Ptr(ref, found->second); + return Ptr(ref, this); + } + void CellStore::moveFrom(const Ptr &object, CellStore *from) { if (mState != State_Loaded) @@ -964,26 +972,26 @@ namespace MWWorld mLastRespawn = MWBase::Environment::get().getWorld()->getTimeStamp(); for (CellRefList::List::iterator it (mContainers.mList.begin()); it!=mContainers.mList.end(); ++it) { - Ptr ptr (&*it, this); + Ptr ptr = getCurrentPtr(&*it); ptr.getClass().respawn(ptr); } } for (CellRefList::List::iterator it (mCreatures.mList.begin()); it!=mCreatures.mList.end(); ++it) { - Ptr ptr (&*it, this); + Ptr ptr = getCurrentPtr(&*it); clearCorpse(ptr); ptr.getClass().respawn(ptr); } for (CellRefList::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it) { - Ptr ptr (&*it, this); + Ptr ptr = getCurrentPtr(&*it); clearCorpse(ptr); ptr.getClass().respawn(ptr); } for (CellRefList::List::iterator it (mCreatureLists.mList.begin()); it!=mCreatureLists.mList.end(); ++it) { - Ptr ptr (&*it, this); + Ptr ptr = getCurrentPtr(&*it); // no need to clearCorpse, handled as part of mCreatures ptr.getClass().respawn(ptr); } diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 1aee131324..aa7d68d8c0 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -111,6 +111,9 @@ namespace MWWorld // Merged list of ref's currently in this cell - i.e. with added refs from mMovedHere, removed refs from mMovedToAnotherCell std::vector mMergedRefs; + // Get the Ptr for the given ref which originated from this cell (possibly moved to another cell at this point). + Ptr getCurrentPtr(MWWorld::LiveCellRefBase* ref); + /// Moves object from the given cell to this cell. void moveFrom(const MWWorld::Ptr& object, MWWorld::CellStore* from);