From f99582e671de2d222c2ecb6504fce4ef1f0ba483 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sun, 9 Jul 2023 09:01:39 +0200 Subject: [PATCH] [Lua] Fix removing from inventory --- apps/openmw/mwlua/objectbindings.cpp | 2 +- apps/openmw/mwworld/inventorystore.cpp | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 24c43d739a..84301fe805 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -378,7 +378,7 @@ namespace MWLua ptr.getRefData().setCount(ptr.getRefData().getCount() + countToRemove); // And now remove properly if (ptr.getContainerStore()) - ptr.getContainerStore()->remove(ptr, countToRemove); + ptr.getContainerStore()->remove(ptr, countToRemove, false); else { MWBase::Environment::get().getWorld()->disable(ptr); diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 69cdb219af..99949a73d4 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -211,13 +211,9 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::findSlot(int slot) cons if (mSlots[slot] == end()) return mSlots[slot]; - if (mSlots[slot]->getRefData().getCount() < 1) - { - // Object has been deleted - // This should no longer happen, since the new remove function will unequip first - throw std::runtime_error( - "Invalid slot, make sure you are not calling RefData::setCount for a container object"); - } + // NOTE: mSlots[slot]->getRefData().getCount() can be zero if the item is marked + // for removal by a Lua script, but the removal action is not yet processed. + // The item will be automatically unequiped in the current frame. return mSlots[slot]; }