diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index c76e322055..5435de07e2 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -19,7 +19,7 @@ opencs_hdrs_noqt (model/doc opencs_units (model/world idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree infotableproxymodel landtexturetableproxymodel - actoradapter + actoradapter idcollection ) diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp new file mode 100644 index 0000000000..d06a47e32b --- /dev/null +++ b/apps/opencs/model/world/idcollection.cpp @@ -0,0 +1,43 @@ +#include "idcollection.hpp" + +namespace CSMWorld +{ + template<> + int IdCollection >::load (ESM::ESMReader& reader, bool base) + { + Pathgrid record; + bool isDeleted = false; + + loadRecord (record, reader, isDeleted); + + std::string id = IdAccessor().getId (record); + int index = this->searchId (id); + + if (record.mPoints.empty() || record.mEdges.empty()) + isDeleted = true; + + if (isDeleted) + { + if (index==-1) + { + // deleting a record that does not exist + // ignore it for now + /// \todo report the problem to the user + return -1; + } + + if (base) + { + this->removeRows (index, 1); + return -1; + } + + std::unique_ptr > baseRecord(new Record(this->getRecord(index))); + baseRecord->mState = RecordBase::State_Deleted; + this->setRecord(index, std::move(baseRecord)); + return index; + } + + return load (record, base, index); + } +} diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 9f834d8fae..bbc49f18c1 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -5,6 +5,7 @@ #include "collection.hpp" #include "land.hpp" +#include "pathgrid.hpp" namespace CSMWorld { @@ -153,6 +154,9 @@ namespace CSMWorld return true; } + + template<> + int IdCollection >::load(ESM::ESMReader& reader, bool base); } #endif diff --git a/apps/opencs/model/world/pathgrid.hpp b/apps/opencs/model/world/pathgrid.hpp index 22d01b0710..ce74d419e4 100644 --- a/apps/opencs/model/world/pathgrid.hpp +++ b/apps/opencs/model/world/pathgrid.hpp @@ -20,7 +20,7 @@ namespace CSMWorld { std::string mId; - void load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection& cells); + void load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection >& cells); void load (ESM::ESMReader &esm, bool &isDeleted); }; } diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 125239e9a3..f6de1d485b 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -873,6 +873,26 @@ namespace MWWorld // A proper fix should be made for future versions of the file format. bool interior = pathgrid.mData.mX == 0 && pathgrid.mData.mY == 0 && mCells->search(pathgrid.mCell) != nullptr; + // deal with mods that have empty pathgrid records (Issue #6209) + // we assume that these records are empty on purpose (i.e. to remove old pathgrid on an updated cell) + if (isDeleted || pathgrid.mPoints.empty() || pathgrid.mEdges.empty()) + { + if (interior) + { + Interior::iterator it = mInt.find(pathgrid.mCell); + if (it != mInt.end()) + mInt.erase(it); + } + else + { + Exterior::iterator it = mExt.find(std::make_pair(pathgrid.mData.mX, pathgrid.mData.mY)); + if (it != mExt.end()) + mExt.erase(it); + } + + return RecordId("", isDeleted); + } + // Try to overwrite existing record if (interior) {