From 6abb96250fb750a71cf05e7684ac6abf0a22c75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Mon, 15 Aug 2022 17:04:37 +0300 Subject: [PATCH 1/2] Fix using the wrong id for insertStatic --- apps/openmw/mwworld/esmstore.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 0c03585e1f..6829101f66 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -249,17 +249,14 @@ namespace MWWorld template const T *insertStatic(const T &x) { - const std::string id = "$dynamic" + std::to_string(mDynamicCount++); - Store &store = const_cast &>(get()); - 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); for (iterator it = mStores.begin(); it != mStores.end(); ++it) { if (it->second == &store) { mIds[ptr->mId] = it->first; From cdcf1393fcab8521644feede483316f3b3d352b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Mon, 15 Aug 2022 17:06:01 +0300 Subject: [PATCH 2/2] Fix increment of dynamic id when player is inserted --- apps/openmw/mwworld/esmstore.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 6829101f66..b4df837936 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -296,13 +296,13 @@ namespace MWWorld template <> inline const ESM::NPC *ESMStore::insert(const ESM::NPC &npc) { - const std::string id = "$dynamic" + std::to_string(mDynamicCount++); - if (Misc::StringUtils::ciEqual(npc.mId, "player")) { return mNpcs.insert(npc); } - else if (mNpcs.search(id) != nullptr) + + const std::string id = "$dynamic" + std::to_string(mDynamicCount++); + if (mNpcs.search(id) != nullptr) { const std::string msg = "Try to override existing record '" + id + "'"; throw std::runtime_error(msg);