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.
This commit is contained in:
SmallJoker 2023-05-18 20:32:55 +02:00 committed by GitHub
parent f393214fef
commit 95a9f4ab7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -964,15 +964,16 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
{ {
setModified(); 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); s32 i = getListIndex(name);
if (i != -1) { if (i != -1) {
m_lists[i]->checkResizeLock(); InventoryList *list = m_lists[i];
delete m_lists[i]; list->setSize(size);
list->clearItems();
m_lists[i] = new InventoryList(name, size, m_itemdef); return list;
m_lists[i]->setModified();
return m_lists[i];
} }
//don't create list with invalid name //don't create list with invalid name