From ba67bf45f837e7296c9e55c47237f669ba233140 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 26 Jan 2014 20:15:22 +0100 Subject: [PATCH] Fix an issue with InventoryStore copy constructor. Don't copy the iterator directly - mContainer will be wrong and comparisons against end() will always fail. This caused an exception when looting a creature that had moved cells. --- apps/openmw/mwworld/inventorystore.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index ea43314e6..5da871d9d 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -34,6 +34,13 @@ void MWWorld::InventoryStore::copySlots (const InventoryStore& store) mSlots.push_back (slot); } + + // some const-trickery, required because of a flaw in the handling of MW-references and the + // resulting workarounds + std::size_t distance = std::distance (const_cast (store).begin(), const_cast (store).mSelectedEnchantItem); + ContainerStoreIterator slot = begin(); + std::advance (slot, distance); + mSelectedEnchantItem = slot; } void MWWorld::InventoryStore::initSlots (TSlots& slots_) @@ -54,18 +61,19 @@ MWWorld::InventoryStore::InventoryStore() MWWorld::InventoryStore::InventoryStore (const InventoryStore& store) : ContainerStore (store) , mSelectedEnchantItem(end()) - , mListener(NULL) - , mUpdatesEnabled(true) { mMagicEffects = store.mMagicEffects; mFirstAutoEquip = store.mFirstAutoEquip; - mSelectedEnchantItem = store.mSelectedEnchantItem; + mListener = store.mListener; + mUpdatesEnabled = store.mUpdatesEnabled; + mPermanentMagicEffectMagnitudes = store.mPermanentMagicEffectMagnitudes; copySlots (store); } MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStore& store) { + mListener = store.mListener; mMagicEffects = store.mMagicEffects; mFirstAutoEquip = store.mFirstAutoEquip; mPermanentMagicEffectMagnitudes = store.mPermanentMagicEffectMagnitudes;