diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 65eabadaa1..20067afefe 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -32,10 +32,10 @@ namespace MWWorld CellStore& emplaceCellStore(ESM::RefId id, const T& cell, ESMStore& store, ESM::ReadersCache& readers, std::unordered_map& cells) { - return cells - .emplace(std::piecewise_construct, std::forward_as_tuple(id), - std::forward_as_tuple(Cell(cell), store, readers)) - .first->second; + const auto [it, inserted] = cells.emplace( + std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple(Cell(cell), store, readers)); + assert(inserted); + return it->second; } const ESM::Cell* createEsmCell(ESM::ExteriorCellLocation location, ESMStore& store) @@ -205,6 +205,7 @@ namespace MWWorld cellStore = &emplaceCellStore(cell4->mId, *cell4, mStore, mReaders, mCells); else return nullptr; + mInteriors.emplace(name, cellStore); } else { @@ -230,7 +231,12 @@ namespace MWWorld { auto it = mCells.find(id); if (it != mCells.end()) - return &it->second; + { + CellStore& cellStore = it->second; + if (forceLoad && cellStore.getState() != CellStore::State_Loaded) + cellStore.load(); + return &cellStore; + } if (id == draftCellId) {