From 95a9f4ab7cc44d1ed2f3664a34a10b7cdbb8fbb2 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 18 May 2023 20:32:55 +0200 Subject: [PATCH] Inventory: Allow InvRef:set_list with new_size >= old_size (#13497) Fixes a regression introduced by enforced checks to work with valid pointers within inventory actions. --- src/inventory.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/inventory.cpp b/src/inventory.cpp index eb7133b41..7c9e6da1a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -964,15 +964,16 @@ InventoryList * Inventory::addList(const std::string &name, u32 size) { setModified(); - // Remove existing lists + // Reset existing lists instead of re-creating if possible. + // InventoryAction::apply() largely caches InventoryList pointers which must not be + // invalidated by Lua API calls (e.g. InvRef:set_list), hence do resize & clear which + // also include the neccessary resize lock checks. s32 i = getListIndex(name); if (i != -1) { - m_lists[i]->checkResizeLock(); - delete m_lists[i]; - - m_lists[i] = new InventoryList(name, size, m_itemdef); - m_lists[i]->setModified(); - return m_lists[i]; + InventoryList *list = m_lists[i]; + list->setSize(size); + list->clearItems(); + return list; } //don't create list with invalid name