From 76262b7809955f6eecaebac06332c5f39fb1a9d5 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Fri, 8 Aug 2014 06:16:52 +0200 Subject: [PATCH] Fixed crash when exiting menu and recalc_pos/all_menus --- src/gui/menu.cpp | 11 ++++++++++- src/gui/menu_manager.hpp | 13 +++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 6625ba826..240f2fa71 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -49,6 +49,8 @@ Menu::Menu() : arrange_left(), active_item() { + MenuManager::instance().m_all_menus.push_back(this); + hit_item = -1; menuaction = MENU_ACTION_NONE; delete_character = 0; @@ -65,6 +67,13 @@ Menu::Menu() : Menu::~Menu() { + MenuManager::instance().m_all_menus.remove(this); + + if (MenuManager::instance().current() == this) + MenuManager::instance().m_current = nullptr; + + if (MenuManager::instance().get_previous() == this) + MenuManager::instance().m_previous = nullptr; } void @@ -195,7 +204,7 @@ Menu::update() effect_progress = 1.0f; if (close) { - MenuManager::instance().current(0); + MenuManager::instance().m_current = 0; close = false; } } diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp index b0fb4be6a..a390c6f0d 100644 --- a/src/gui/menu_manager.hpp +++ b/src/gui/menu_manager.hpp @@ -31,11 +31,15 @@ public: public: std::vector m_last_menus; - std::vector m_all_menus; + std::list m_all_menus; + /** Used only for transition effects */ Menu* m_previous; + Menu* m_current; + friend class Menu; + public: MenuManager(); ~MenuManager(); @@ -59,13 +63,6 @@ public: return m_current; } - - /** Return the current active menu or NULL if none is active */ - void current(Menu* menu) - { - m_current = menu; - } - private: MenuManager(const MenuManager&); MenuManager& operator=(const MenuManager&); -- 2.11.0