From dafe184220dc2790435c212e7bbe43fe9ccc1ebb Mon Sep 17 00:00:00 2001 From: MiroslavR Date: Fri, 22 Jul 2016 02:12:03 +0200 Subject: [PATCH] Fix moved references disappearing when modified by a plugin --- apps/openmw/mwworld/store.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index fbe94b7d0..c13f10d9a 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -675,14 +675,17 @@ namespace MWWorld for (ESM::MovedCellRefTracker::const_iterator it = cell.mMovedRefs.begin(); it != cell.mMovedRefs.end(); ++it) { // remove reference from current leased ref tracker and add it to new cell ESM::MovedCellRefTracker::iterator itold = std::find(oldcell->mMovedRefs.begin(), oldcell->mMovedRefs.end(), it->mRefNum); - if (itold != oldcell->mMovedRefs.end()) { - ESM::MovedCellRef target0 = *itold; - ESM::Cell *wipecell = const_cast(search(target0.mTarget[0], target0.mTarget[1])); - ESM::CellRefTracker::iterator it_lease = std::find_if(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(it->mRefNum)); - if (it_lease != wipecell->mLeasedRefs.end()) - wipecell->mLeasedRefs.erase(it_lease); - else - std::cerr << "can't find " << it->mRefNum.mIndex << " " << it->mRefNum.mContentFile << " in leasedRefs " << std::endl; + if (itold != oldcell->mMovedRefs.end()) + { + if (it->mTarget[0] != itold->mTarget[0] || it->mTarget[1] != itold->mTarget[1]) + { + ESM::Cell *wipecell = const_cast(search(itold->mTarget[0], itold->mTarget[1])); + ESM::CellRefTracker::iterator it_lease = std::find_if(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(it->mRefNum)); + if (it_lease != wipecell->mLeasedRefs.end()) + wipecell->mLeasedRefs.erase(it_lease); + else + std::cerr << "can't find " << it->mRefNum.mIndex << " " << it->mRefNum.mContentFile << " in leasedRefs " << std::endl; + } *itold = *it; } else