diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index a3a4c14952..8d5ca4518c 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -192,6 +192,12 @@ int MWWorld::ContainerStore::count(const ESM::RefId& id) const return total; } +void MWWorld::ContainerStore::clearRefNums() +{ + for (const auto& iter : *this) + iter.getCellRef().unsetRefNum(); +} + MWWorld::ContainerStoreListener* MWWorld::ContainerStore::getContListener() const { return mListener; diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index e0fa3fecd7..9d02e0b95c 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -102,6 +102,10 @@ namespace MWWorld protected: ContainerStoreListener* mListener; + // Used in clone() to unset refnums of copies. + // (RefNum should be unique, copy can not have the same RefNum). + void clearRefNums(); + // (item, max charge) typedef std::vector> TRechargingItems; TRechargingItems mRechargingItems; @@ -165,7 +169,12 @@ namespace MWWorld virtual ~ContainerStore(); - virtual std::unique_ptr clone() { return std::make_unique(*this); } + virtual std::unique_ptr clone() + { + auto res = std::make_unique(*this); + res->clearRefNums(); + return res; + } ConstContainerStoreIterator cbegin(int mask = Type_All) const; ConstContainerStoreIterator cend() const; diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index a0c050e420..78d7e35275 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -97,7 +97,12 @@ namespace MWWorld const MWWorld::Ptr& getActor() const { return mActor; } void setActor(const MWWorld::Ptr& actor) { mActor = actor; } - std::unique_ptr clone() override { return std::make_unique(*this); } + std::unique_ptr clone() override + { + auto res = std::make_unique(*this); + res->clearRefNums(); + return res; + } ContainerStoreIterator add( const Ptr& itemPtr, int count, bool allowAutoEquip = true, bool resolve = true) override;