summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-29 14:31:02 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-29 14:31:02 +0300
commitab9e0ea04e66e3d3866e5bad678ffc4177a11781 (patch)
tree273918c1c33cda9d7b74fa6b408b817cf1e8c5bd
parent3ef886b241c5654bf21e5326d1299ccde161b228 (diff)
downloadplus-ab9e0ea04e66e3d3866e5bad678ffc4177a11781.tar.gz
plus-ab9e0ea04e66e3d3866e5bad678ffc4177a11781.tar.bz2
plus-ab9e0ea04e66e3d3866e5bad678ffc4177a11781.tar.xz
plus-ab9e0ea04e66e3d3866e5bad678ffc4177a11781.zip
fix crash if open rename map item dialog and walk to other map.
-rw-r--r--src/gui/popupmenu.cpp32
-rw-r--r--src/gui/popupmenu.h6
2 files changed, 24 insertions, 14 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index c12365cc6..410064f7d 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -2668,14 +2668,29 @@ void PopupMenu::showGMPopup()
RenameListener::RenameListener() :
gcn::ActionListener(),
- mMapItem(nullptr),
+ mMapItemX(0),
+ mMapItemY(0),
mDialog(nullptr)
{
}
+void RenameListener::setMapItem(MapItem *const mapItem)
+{
+ if (mapItem)
+ {
+ mMapItemX = mapItem->getX();
+ mMapItemY = mapItem->getY();
+ }
+ else
+ {
+ mMapItemX = 0;
+ mMapItemY = 0;
+ }
+}
+
void RenameListener::action(const gcn::ActionEvent &event)
{
- if (event.getId() == "ok" && mMapItem && viewport && mDialog)
+ if (event.getId() == "ok" && viewport && mDialog)
{
Map *const map = viewport->getMap();
if (!map)
@@ -2685,16 +2700,11 @@ void RenameListener::action(const gcn::ActionEvent &event)
MapItem *item = nullptr;
if (sl)
{
- item = sl->getTile(mMapItem->getX(), mMapItem->getY());
- if (!item)
- {
- sl->setTile(mMapItem->getX(), mMapItem->getY(),
- mMapItem->getType());
- item = sl->getTile(mMapItem->getX(), mMapItem->getY());
- }
- item->setComment(mDialog->getText());
+ item = sl->getTile(mMapItemX, mMapItemY);
+ if (item)
+ item->setComment(mDialog->getText());
}
- item = map->findPortalXY(mMapItem->getX(), mMapItem->getY());
+ item = map->findPortalXY(mMapItemX, mMapItemY);
if (item)
item->setComment(mDialog->getText());
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 069fb466a..3865c2bd3 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -56,14 +56,14 @@ class RenameListener final : public gcn::ActionListener
void action(const gcn::ActionEvent &event) override;
- void setMapItem(MapItem* mapItem)
- { mMapItem = mapItem; }
+ void setMapItem(MapItem *const mapItem);
void setDialog(TextDialog *dialog)
{ mDialog = dialog; }
private:
- MapItem *mMapItem;
+ int mMapItemX;
+ int mMapItemY;
TextDialog *mDialog;
};