diff options
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.h | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 75ef1e852..773f43ff7 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -820,13 +820,15 @@ void ItemContainer::updateMatrix() delete sortedItems[idx]; } -int ItemContainer::getSlotIndex(const int x, const int y) const +int ItemContainer::getSlotIndex(int x, int y) const { if (!mShowMatrix) return Inventory::NO_SLOT_INDEX; if (x < mDimension.width && y < mDimension.height && x >= 0 && y >= 0) { + if (x > mBoxWidth * mGridColumns) + return Inventory::NO_SLOT_INDEX; const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth); if (idx >= 0 && idx < mGridRows * mGridColumns && mShowMatrix[idx] >= 0) diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 243104ead..f87eac55d 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -171,7 +171,7 @@ class ItemContainer final : public Widget, * @param y The Y coordinate position. * @return The slot index on success, -1 on failure. */ - int getSlotIndex(const int x, const int y) const; + int getSlotIndex(int x, int y) const; Inventory *mInventory; Image *mSelImg; |