From 6f501e2f687df1550dfc024f7ac5d36a5b88d548 Mon Sep 17 00:00:00 2001 From: Chuck Miller Date: Mon, 11 May 2009 21:31:35 -0400 Subject: Makes sure a item exists in the inventory before saying it is selected Was causing a lot of issues (mainly segfaults) when things were used/dropped/stored/retrieved --- src/gui/itemcontainer.cpp | 14 ++++++++++++++ src/gui/itemcontainer.h | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 4779b004..d2712cba 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -320,6 +320,20 @@ void ItemContainer::widgetResized(const gcn::Event &event) setHeight(mGridRows * BOX_HEIGHT); } +Item *ItemContainer::getSelectedItem() +{ + if (!mSelectedItem) + return NULL; + + if (!mInventory->contains(mSelectedItem)) + { + mSelectedItem = NULL; + return NULL; + } + + return mSelectedItem; +} + int ItemContainer::getSlotIndex(int x, int y) const { if (x < getWidth() && y < getHeight()) diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index bc7caf5d..54d7c35e 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -86,8 +86,7 @@ class ItemContainer : public gcn::Widget, /** * Returns the selected item. */ - Item *getSelectedItem() const - { return mSelectedItem; } + Item *getSelectedItem(); /** * Sets selected item to NULL. -- cgit v1.2.3-70-g09d2