From e7120f189b2ca6339a0c13c472a6a3853efd6179 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Tue, 17 Jan 2023 03:04:34 +0100 Subject: [PATCH] Unset RefNums after copying containers (otherwise copies will have the same RefNums, but they should be unique) --- apps/openmw/mwworld/containerstore.cpp | 6 ++++++ apps/openmw/mwworld/containerstore.hpp | 11 ++++++++++- apps/openmw/mwworld/inventorystore.hpp | 7 ++++++- 3 files changed, 22 insertions(+), 2 deletions(-) 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;