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);
}
/*
- 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);
+ }
}
/*
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
/*
GUIFormSpecMenu
*/
-
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
InventoryManager *invmgr, IGameDef *gamedef,
ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
- GUIFormSpecMenu** ext_ptr, Client* client) :
+ Client* client) :
GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
m_device(dev),
m_invmgr(invmgr),
m_lock(false),
m_form_src(fsrc),
m_text_dst(tdst),
- m_ext_ptr(ext_ptr),
m_font(dev->getGUIEnvironment()->getSkin()->getFont()),
m_formspec_version(0)
#ifdef __ANDROID__
if (m_text_dst != NULL) {
delete m_text_dst;
}
-
- if (m_ext_ptr != NULL) {
- assert(*m_ext_ptr == this);
- *m_ext_ptr = NULL;
- }
}
void GUIFormSpecMenu::removeChildren()