From 81d9686541f2bfeed6e8a84dbd1b29a2f894b802 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 22 Apr 2023 19:12:24 +0200 Subject: [PATCH] crashfix dynamic exterior cells --- apps/openmw/mwworld/store.cpp | 21 +++++++++++++++++++-- apps/openmw/mwworld/store.hpp | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 95cf1bca22..be6196c3fb 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1127,7 +1127,8 @@ namespace MWWorld ESM4::Cell* Store::insert(const ESM4::Cell& item, bool overrideOnly) { auto cellPtr = TypedDynamicStore::insert(item, overrideOnly); - mCellNameIndex[cellPtr->mEditorId] = cellPtr; + if (!cellPtr->mEditorId.empty()) + mCellNameIndex[cellPtr->mEditorId] = cellPtr; if (cellPtr->isExterior()) mExteriors[cellPtr->mParent][std::make_pair(cellPtr->getGridX(), cellPtr->getGridY())] = cellPtr; @@ -1137,12 +1138,28 @@ namespace MWWorld ESM4::Cell* Store::insertStatic(const ESM4::Cell& item) { auto cellPtr = TypedDynamicStore::insertStatic(item); - mCellNameIndex[cellPtr->mEditorId] = cellPtr; + if (!cellPtr->mEditorId.empty()) + mCellNameIndex[cellPtr->mEditorId] = cellPtr; if (cellPtr->isExterior()) mExteriors[cellPtr->mParent][std::make_pair(cellPtr->getGridX(), cellPtr->getGridY())] = cellPtr; return cellPtr; } + + void Store::clearDynamic() + { + for (auto& cellToDeleteIt : mDynamic) + { + ESM4::Cell& cellToDelete = cellToDeleteIt.second; + if (cellToDelete.isExterior()) + { + mExteriors[cellToDelete.mParent].erase(std::make_pair(cellToDelete.mX, cellToDelete.mY)); + } + if (!cellToDelete.mEditorId.empty()) + mCellNameIndex.erase(cellToDelete.mEditorId); + } + MWWorld::TypedDynamicStore::clearDynamic(); + } } template class MWWorld::TypedDynamicStore; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 95591d67b8..b17fde68b6 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -177,6 +177,7 @@ namespace MWWorld template class TypedDynamicStore : public DynamicStoreBase { + protected: typedef std::unordered_map Static; Static mStatic; /// @par mShared usually preserves the record order as it came from the content files (this @@ -290,6 +291,7 @@ namespace MWWorld bool exteriorExists(ESM::RefId worldspace) const; ESM4::Cell* insert(const ESM4::Cell& item, bool overrideOnly = false); ESM4::Cell* insertStatic(const ESM4::Cell& item); + void clearDynamic() override; }; template <>