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
1 changed files with 8 additions and 7 deletions

View File

@ -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