fix(inventory): a removed item is freed by its inventory, not by itself (issue 1568)

Item::RemoveFromInventory ended with `delete this`, so every caller that still used the item afterwards (SetCount(0)
returning into its caller, loops that remove several items, proxies purged while their parent is handled) touched
freed memory. The inventory now takes the removed item and frees it at the inventory component's next update, or
with the inventory.

Check in game: sell, drop, delete, trade, mail and use up stacks (including the last of a stack); unequip and
remove an item set piece and a proxy-bearing item (rocket, modular car); donate items; nothing crashes and the
inventory shows the right counts after relogging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 10:52:22 -05:00
parent 1aa70c523b
commit 585e2a6ace
6 changed files with 127 additions and 1 deletions

View File

@@ -964,6 +964,11 @@ void InventoryComponent::Update(float deltaTime) {
for (auto* set : m_Itemsets) {
set->Update(deltaTime);
}
// Items removed during the last frame are no longer in use
for (auto* const inventory : m_Inventories | std::views::values) {
inventory->FreeRetiredItems();
}
}
void InventoryComponent::UpdateSlot(const std::string& location, const EquippedItem& item, bool keepCurrent) {