From 810ba6190921572d3ac01cfb5d82bbe4b7fb171d Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sat, 27 Sep 2014 17:46:48 +1000 Subject: [PATCH 1/3] While loading overwrite records with the same id. Should resolve bug #1750. --- apps/opencs/model/world/collection.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 1fb3e1f1d..387b33cf3 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -431,18 +432,27 @@ namespace CSMWorld const Record& record2 = dynamic_cast&> (record); - mRecords.insert (mRecords.begin()+index, record2); + std::pair::iterator, bool> insertResult = + mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (record2.get())), + index)); + + if(!insertResult.second) // duplicate index found, replace the current record + { + std::cerr << "Duplicate record found, using new: " + IdAccessorT().getId(record2.get()) << std::endl; + replace(insertResult.first->second, record2); + return; + } + // else update the index except for the record to be inserted if (index (mRecords.size())-1) { - for (std::map::iterator iter (mIndex.begin()); iter!=mIndex.end(); - ++iter) - if (iter->second>=index) + std::string id = IdAccessorT().getId(record2.get()); + for (std::map::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter) + if (iter->second > index || (iter->second == index && iter->first != id)) ++(iter->second); } - mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId ( - record2.get())), index)); + mRecords.insert (mRecords.begin()+index, record2); } template From a2d043f43a31195acd357f937a9cc8d9c5534b26 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sat, 27 Sep 2014 23:36:27 +1000 Subject: [PATCH 2/3] Re-check unknown record id after loading. --- apps/opencs/model/world/idcollection.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 7e7756ff3..940181c24 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -71,6 +71,14 @@ namespace CSMWorld record.load (reader); + if (index==-1) + { + std::string newId = IdAccessorT().getId(record); + int newIndex = this->searchId(newId); + if (newIndex != -1 && id != newId) + index = newIndex; + } + load (record, base, index); } } From d790b8edfa5d41107fb5f55e3eecf0455679f660 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sat, 27 Sep 2014 23:39:22 +1000 Subject: [PATCH 3/3] Revert old fix. --- apps/opencs/model/world/collection.hpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 387b33cf3..1fb3e1f1d 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include @@ -432,27 +431,18 @@ namespace CSMWorld const Record& record2 = dynamic_cast&> (record); - std::pair::iterator, bool> insertResult = - mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (record2.get())), - index)); - - if(!insertResult.second) // duplicate index found, replace the current record - { - std::cerr << "Duplicate record found, using new: " + IdAccessorT().getId(record2.get()) << std::endl; - replace(insertResult.first->second, record2); - return; - } + mRecords.insert (mRecords.begin()+index, record2); - // else update the index except for the record to be inserted if (index (mRecords.size())-1) { - std::string id = IdAccessorT().getId(record2.get()); - for (std::map::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter) - if (iter->second > index || (iter->second == index && iter->first != id)) + for (std::map::iterator iter (mIndex.begin()); iter!=mIndex.end(); + ++iter) + if (iter->second>=index) ++(iter->second); } - mRecords.insert (mRecords.begin()+index, record2); + mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId ( + record2.get())), index)); } template