Skip to content

Commit

Permalink
bug: error when inventory slots fills up
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil McGill committed Jul 2, 2023
1 parent b837060 commit 5348ff3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/thing_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,25 @@

void Thing::inventory_particle(Thingp item, int slot)
{
dbg("Create inventory particle? %s", item->to_short_string().c_str());
dbg("Create inventory particle to slot %d? %s", slot, item->to_short_string().c_str());
TRACE_AND_INDENT();

auto itemsp = maybe_itemsp();
if (! itemsp) {
ERR("No itemsp for player");
return;
}

if (slot < 0) {
DBG("Slot %d out of range, max %d", slot, (int) itemsp->inventory_shortcuts.size());
return ;
}

if (slot >= (int) itemsp->inventory_shortcuts.size()) {
DBG("Slot %d out of range, max %d", slot, (int) itemsp->inventory_shortcuts.size());
return ;
}

//
// No animations at the start
//
Expand Down Expand Up @@ -638,6 +654,11 @@ Thingp Level::inventory_get(const int slot)
return nullptr;
}

if (slot < 0) {
DBG("Slot %d out of range, max %d", slot, (int) itemsp->inventory_shortcuts.size());
return nullptr;
}

if (slot >= (int) itemsp->inventory_shortcuts.size()) {
DBG("Slot %d out of range, max %d", slot, (int) itemsp->inventory_shortcuts.size());
return nullptr;
Expand Down

0 comments on commit 5348ff3

Please sign in to comment.