summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-05-11 21:31:35 -0400
committerChuck Miller <shadowmil@gmail.com>2009-05-11 21:31:35 -0400
commit6f501e2f687df1550dfc024f7ac5d36a5b88d548 (patch)
treee658c14bd2fa7eca519bb7ec3e550175f1efcbe4 /src
parent75cd80b9eaee9526bfe1625ad63eccdb7c212161 (diff)
downloadmana-6f501e2f687df1550dfc024f7ac5d36a5b88d548.tar.gz
mana-6f501e2f687df1550dfc024f7ac5d36a5b88d548.tar.bz2
mana-6f501e2f687df1550dfc024f7ac5d36a5b88d548.tar.xz
mana-6f501e2f687df1550dfc024f7ac5d36a5b88d548.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemcontainer.cpp14
-rw-r--r--src/gui/itemcontainer.h3
2 files changed, 15 insertions, 2 deletions
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.