summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2009-07-15 22:37:35 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2009-07-15 22:37:35 +0200
commitfa6d39d9f56e09abfb6b48bacdd66ddbad20c641 (patch)
tree31a57b7a69c20454e129963e2b2c4327782a2311 /src
parentdf52e6b900600709ab0069daacf06093c61667b1 (diff)
downloadmana-fa6d39d9f56e09abfb6b48bacdd66ddbad20c641.tar.gz
mana-fa6d39d9f56e09abfb6b48bacdd66ddbad20c641.tar.bz2
mana-fa6d39d9f56e09abfb6b48bacdd66ddbad20c641.tar.xz
mana-fa6d39d9f56e09abfb6b48bacdd66ddbad20c641.zip
Fixed compile warnings and crash in skill dialog
The crash was probably due to roaming or uninitialized pointers in the skill map. Please remember to clear it after deleting its contents, and also remember that operator[] is non-const and will insert an element when it's not already there. The proper way to see if a map contains an element is by using find().
Diffstat (limited to 'src')
-rw-r--r--src/gui/skilldialog.cpp27
-rw-r--r--src/net/ea/specialhandler.cpp8
2 files changed, 19 insertions, 16 deletions
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 5e700387..15f93b9c 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -62,7 +62,7 @@ struct SkillInfo
class SkillEntry : public Container, gcn::WidgetListener
{
public:
- SkillEntry(struct SkillInfo *info);
+ SkillEntry(SkillInfo *info);
void widgetResized(const gcn::Event &event);
@@ -70,7 +70,7 @@ class SkillEntry : public Container, gcn::WidgetListener
protected:
friend class SkillDialog;
- struct SkillInfo *mInfo;
+ SkillInfo *mInfo;
private:
Icon *mIcon;
@@ -152,15 +152,16 @@ void SkillDialog::logic()
std::string SkillDialog::update(int id)
{
- SkillInfo *info = mSkills[id];
+ SkillMap::iterator i = mSkills.find(id);
- if (info)
+ if (i != mSkills.end())
{
+ SkillInfo *info = i->second;
info->display->update();
return info->name;
}
- else
- return "";
+
+ return std::string();
}
void SkillDialog::update()
@@ -180,6 +181,7 @@ void SkillDialog::loadSkills(const std::string &file)
{
// TODO: mTabs->clear();
delete_all(mSkills);
+ mSkills.clear();
XML::Document doc(file);
xmlNodePtr root = doc.rootNode();
@@ -239,21 +241,23 @@ void SkillDialog::loadSkills(const std::string &file)
void SkillDialog::setModifiable(int id, bool modifiable)
{
- SkillInfo *info = mSkills[id];
+ SkillMap::iterator i = mSkills.find(id);
- if (info)
+ if (i != mSkills.end())
{
+ SkillInfo *info = i->second;
info->modifiable = modifiable;
info->display->update();
}
}
-SkillEntry::SkillEntry(struct SkillInfo *info) : mInfo(info),
+SkillEntry::SkillEntry(SkillInfo *info) :
+ mInfo(info),
mIcon(NULL),
mNameLabel(new Label(info->name)),
- mProgress(new ProgressBar(0.0f, 200, 20, gcn::Color(150, 150, 150))),
+ mLevelLabel(new Label("999")),
mIncrease(new Button("+", "inc", skillDialog)),
- mLevelLabel(new Label("999"))
+ mProgress(new ProgressBar(0.0f, 200, 20, gcn::Color(150, 150, 150)))
{
setFrameSize(1);
setOpaque(false);
@@ -312,7 +316,6 @@ void SkillEntry::widgetResized(const gcn::Event &event)
void SkillEntry::update()
{
int baseLevel = player_node->getAttributeBase(mInfo->id);
-
int effLevel = player_node->getAttributeEffective(mInfo->id);
if (baseLevel <= 0 && !mInfo->modifiable)
diff --git a/src/net/ea/specialhandler.cpp b/src/net/ea/specialhandler.cpp
index 218ff795..528f531e 100644
--- a/src/net/ea/specialhandler.cpp
+++ b/src/net/ea/specialhandler.cpp
@@ -100,8 +100,8 @@ void SpecialHandler::handleMessage(MessageIn &msg)
msg.readInt16(); // target type
msg.skip(2); // unused
int level = msg.readInt16();
- int sp = msg.readInt16();
- int range = msg.readInt16();
+ msg.readInt16(); // sp
+ msg.readInt16(); // range
msg.skip(24); // unused
int up = msg.readInt8();
@@ -115,8 +115,8 @@ void SpecialHandler::handleMessage(MessageIn &msg)
{
skillId = msg.readInt16();
int level = msg.readInt16();
- int sp = msg.readInt16();
- int range = msg.readInt16();
+ msg.readInt16(); // sp
+ msg.readInt16(); // range
int up = msg.readInt8();
player_node->setAttributeBase(skillId, level);