From 57df51b4a6098f36b9df7bdf1bdd1b08cd04bbf6 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Mon, 5 Sep 2022 18:04:10 +0200 Subject: [PATCH] fixed made by @ZehMatt in 6abb96250fb750a71cf05e7684ac6abf0a22c75d and cdcf1393fcab8521644feede483316f3b3d352b0 --- apps/openmw/mwworld/esmstore.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index e09c8f260c..615bfb7d6f 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -233,17 +233,14 @@ namespace MWWorld template static const T *esm3insertStatic(ESMStore& stores, const T &x) { - const std::string id = "$dynamic" + std::to_string(stores.mDynamicCount++); - Store &store = stores.getWritable(); - if (store.search(id) != nullptr) + if (store.search(x.mId) != nullptr) { - const std::string msg = "Try to override existing record '" + id + "'"; + const std::string msg = "Try to override existing record '" + x.mId + "'"; throw std::runtime_error(msg); } - T record = x; - T *ptr = store.insertStatic(record); + T *ptr = store.insertStatic(x); auto esm3RecordType_find = stores.mStoreImp->mStoreToRecName.find(&stores.get()); if (esm3RecordType_find != stores.mStoreImp->mStoreToRecName.end()) { @@ -769,13 +766,14 @@ void ESMStore::removeMissingObjects(Store& store) template <> const ESM::NPC *ESMStore::insert(const ESM::NPC &npc) { - const std::string id = "$dynamic" + std::to_string(mDynamicCount++); + auto& npcs = getWritable(); if (Misc::StringUtils::ciEqual(npc.mId, "player")) { return npcs.insert(npc); } - else if (npcs.search(id) != nullptr) + const std::string id = "$dynamic" + std::to_string(mDynamicCount++); + if (npcs.search(id) != nullptr) { const std::string msg = "Try to override existing record '" + id + "'"; throw std::runtime_error(msg);