Treat container iterators to stacks of count 0 like end iterators

This commit is contained in:
Evil Eye
2026-04-27 10:13:56 +02:00
parent 19e8ce3c8d
commit 0bf0f61309
2 changed files with 10 additions and 7 deletions
+8 -5
View File
@@ -127,7 +127,8 @@ void MWWorld::ContainerStore::readEquipmentState(
std::ptrdiff_t MWWorld::ContainerStore::index(const ContainerStoreIterator& iter) const
{
if (iter.getType() == -1)
// A count of 0 means the item is being removed/teleported by Lua
if (iter.getType() == -1 || !iter->getCellRef().getCount())
return -1;
return std::distance(cbegin(), ConstContainerStoreIterator(iter));
}
@@ -175,10 +176,11 @@ MWWorld::ContainerStore::ContainerStore(const MWWorld::ContainerStore& store)
, mResolved(store.mResolved)
, mRechargingItemsUpToDate(false)
{
if (store.mSelectedEnchantItem != store.end())
const std::ptrdiff_t distance = store.index(store.mSelectedEnchantItem);
if (distance != -1)
{
mSelectedEnchantItem = begin();
std::advance(mSelectedEnchantItem, store.index(store.mSelectedEnchantItem));
std::advance(mSelectedEnchantItem, distance);
}
}
@@ -217,10 +219,11 @@ MWWorld::ContainerStore& MWWorld::ContainerStore::operator=(const ContainerStore
mModified = store.mModified;
mResolved = store.mResolved;
mRechargingItemsUpToDate = false;
if (store.mSelectedEnchantItem != store.end())
const std::ptrdiff_t distance = store.index(store.mSelectedEnchantItem);
if (distance != -1)
{
mSelectedEnchantItem = begin();
std::advance(mSelectedEnchantItem, store.index(store.mSelectedEnchantItem));
std::advance(mSelectedEnchantItem, distance);
}
else
mSelectedEnchantItem = end();
+2 -2
View File
@@ -19,12 +19,12 @@ void MWWorld::InventoryStore::copySlots(const InventoryStore& store)
{
for (const MWWorld::ContainerStoreIterator& it : store.mSlots)
{
if (it == store.end())
const std::ptrdiff_t distance = store.index(it);
if (distance == -1)
{
mSlots.push_back(end());
continue;
}
const std::ptrdiff_t distance = store.index(it);
ContainerStoreIterator slot = begin();
std::advance(slot, distance);
mSlots.push_back(slot);