summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2014-10-24 16:22:05 +0200
committerKahrl <kahrl@gmx.net>2014-10-24 21:14:48 +0200
commitb49e5cfc7013cef7e9af79d17e04f7e7e4c377d4 (patch)
tree7b8c98c13f4598dba70f2c30118f8f5b7bebcac7 /src/game.cpp
parent73bf791fe12d4214d29b6b872940ede634651ce8 (diff)
downloadminetest-b49e5cfc7013cef7e9af79d17e04f7e7e4c377d4.tar.gz
minetest-b49e5cfc7013cef7e9af79d17e04f7e7e4c377d4.tar.bz2
minetest-b49e5cfc7013cef7e9af79d17e04f7e7e4c377d4.zip
Remove m_ext_ptr in GUIFormSpecMenu, replaced by refcount mechanism
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 2f228b0ed..2e4485e36 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -944,9 +944,16 @@ static inline void create_formspec_menu(GUIFormSpecMenu** cur_formspec,
if (*cur_formspec == 0) {
*cur_formspec = new GUIFormSpecMenu(device, guiroot, -1, &g_menumgr,
- invmgr, gamedef, tsrc, fs_src, txt_dest, cur_formspec, client);
+ invmgr, gamedef, tsrc, fs_src, txt_dest, client);
(*cur_formspec)->doPause = false;
- (*cur_formspec)->drop();
+
+ /*
+ Caution: do not call (*cur_formspec)->drop() here --
+ the reference might outlive the menu, so we will
+ periodically check if *cur_formspec is the only
+ remaining reference (i.e. the menu was removed)
+ and delete it in that case.
+ */
}
else {
(*cur_formspec)->setFormSource(fs_src);
@@ -3417,10 +3424,16 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
}
/*
- make sure menu is on top
+ 1. Delete formspec menu reference if menu was removed
+ 2. Else, make sure formspec menu is on top
*/
- if ((!noMenuActive()) && (current_formspec)) {
+ if (current_formspec) {
+ if (current_formspec->getReferenceCount() == 1) {
+ current_formspec->drop();
+ current_formspec = NULL;
+ } else if (!noMenuActive()) {
guiroot->bringToFront(current_formspec);
+ }
}
/*
@@ -3509,6 +3522,11 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
g_menumgr.m_stack.front()->setVisible(false);
g_menumgr.deletingMenu(g_menumgr.m_stack.front());
}
+ if (current_formspec) {
+ current_formspec->drop();
+ current_formspec = NULL;
+ }
+
/*
Draw a "shutting down" screen, which will be shown while the map
generator and other stuff quits