Skip to content

Commit

Permalink
Refactor: Catch invalid arguments to addItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ataulien committed Aug 4, 2019
1 parent b064eb3 commit 5ce1261
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace REGoth
REGOTH_LOG(Info, Uncategorized, "[Inventory] Add {0}x item {1} to Inventory of {2}", count,
instance, SO()->getName());

if (count == 0)
{
REGOTH_THROW(InvalidParametersException, "Count cannot be 0");
}

mItemCountByInstance[instance] += 1;

OnItemChanged(instance);
Expand Down
5 changes: 5 additions & 0 deletions src/components/UIInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ namespace REGoth
{
auto it = mItemsByInstance.find(instance);

if (count == 0)
{
REGOTH_THROW(InvalidParametersException, "Count cannot be 0");
}

if (it == mItemsByInstance.end())
{
auto& item = mItemsByInstance[instance];
Expand Down

0 comments on commit 5ce1261

Please sign in to comment.