From d27b92e9f1b093798cbe2404ed0b998c8f3b750f Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Fri, 22 May 2015 00:57:47 +0300 Subject: [PATCH] Avoid gaps between local indexes in RefIdData after removal of records (Fix #2545) --- apps/opencs/model/world/refiddata.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index f67ab2152..7f5c25f36 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -176,7 +176,6 @@ void CSMWorld::RefIdData::erase (const LocalIndex& index, int count) { std::map::iterator iter = mRecordContainers.find (index.second); - if (iter==mRecordContainers.end()) throw std::logic_error ("invalid local index type"); @@ -189,6 +188,20 @@ void CSMWorld::RefIdData::erase (const LocalIndex& index, int count) mIndex.erase (result); } + // Adjust the local indexes to avoid gaps between them after removal of records + int recordIndex = index.first + count; + int recordCount = iter->second->getSize(); + while (recordIndex < recordCount) + { + std::map::iterator recordIndexFound = + mIndex.find(Misc::StringUtils::lowerCase(iter->second->getId(recordIndex))); + if (recordIndexFound != mIndex.end()) + { + recordIndexFound->second.first -= count; + } + ++recordIndex; + } + iter->second->erase (index.first, count); }