diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-03-02 21:55:47 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-03-02 22:02:52 +0100 |
commit | 4f422bd50c51d812fb9e50f2610c2cd37ead8ef2 (patch) | |
tree | 5c257b7c611e7bd519265bcfcb33a882804acf35 /src/gui/skilldialog.cpp | |
parent | 2a70d4ba6e789075cd9bee1fea4f757186d68f76 (diff) | |
download | mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.gz mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.bz2 mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.xz mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.zip |
Fixed crash when trying to increase non-selected skill
Reviewed-by: Jared Adams
Reviewed-by: Bertram
Diffstat (limited to 'src/gui/skilldialog.cpp')
-rw-r--r-- | src/gui/skilldialog.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index d53a1867..09c7ccb2 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -77,7 +77,7 @@ struct SkillInfo icon->decRef(); } - void setIcon(std::string iconPath) + void setIcon(const std::string &iconPath) { ResourceManager *res = ResourceManager::getInstance(); if (!iconPath.empty()) @@ -100,11 +100,19 @@ typedef std::vector<SkillInfo*> SkillList; class SkillModel : public gcn::ListModel { public: - int getNumberOfElements() { return mVisibleSkills.size(); } - SkillInfo *getSkillAt(int i) { return mVisibleSkills.at(i); } - std::string getElementAt(int i) { return getSkillAt(i)->name; } + int getNumberOfElements() + { return mVisibleSkills.size(); } + + SkillInfo *getSkillAt(int i) const + { return mVisibleSkills.at(i); } + + std::string getElementAt(int i) + { return getSkillAt(i)->name; } + void updateVisibilities(); - void addSkill(SkillInfo *info) { mSkills.push_back(info); } + + void addSkill(SkillInfo *info) + { mSkills.push_back(info); } private: SkillList mSkills; @@ -120,7 +128,11 @@ public: SkillInfo *getSelectedInfo() { - return static_cast<SkillModel*>(mListModel)->getSkillAt(getSelected()); + const int selected = getSelected(); + if (selected < 0 || selected > mListModel->getNumberOfElements()) + return 0; + + return static_cast<SkillModel*>(mListModel)->getSkillAt(selected); } void draw(gcn::Graphics *gcnGraphics) @@ -217,9 +229,8 @@ void SkillDialog::action(const gcn::ActionEvent &event) if (tab) { - SkillInfo *info = tab->getSelectedInfo(); - - Net::getPlayerHandler()->increaseSkill(info->id); + if (SkillInfo *info = tab->getSelectedInfo()) + Net::getPlayerHandler()->increaseSkill(info->id); } } else if (event.getId() == "close") |