1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-10 21:40:15 +00:00

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.
This commit is contained in:
scrawl 2014-01-26 20:15:22 +01:00
parent 365ae15532
commit ba67bf45f8

View File

@ -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<InventoryStore&> (store).begin(), const_cast<InventoryStore&> (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;