diff options
author | Chuck Miller <shadowmil@gmail.com> | 2009-05-11 21:31:35 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-05-11 21:31:35 -0400 |
commit | 6f501e2f687df1550dfc024f7ac5d36a5b88d548 (patch) | |
tree | e658c14bd2fa7eca519bb7ec3e550175f1efcbe4 | |
parent | 75cd80b9eaee9526bfe1625ad63eccdb7c212161 (diff) | |
download | mana-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
-rw-r--r-- | src/gui/itemcontainer.cpp | 14 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 3 |
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. |