Skip to content

Commit

Permalink
Fixed crash when exiting menu and recalc_pos/all_menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 8, 2014
1 parent 7ba504d commit 76262b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/gui/menu.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -195,7 +204,7 @@ Menu::update()
effect_progress = 1.0f;

if (close) {
MenuManager::instance().current(0);
MenuManager::instance().m_current = 0;
close = false;
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/gui/menu_manager.hpp
Expand Up @@ -31,11 +31,15 @@ class MenuManager

public:
std::vector<Menu*> m_last_menus;
std::vector<Menu*> m_all_menus;
std::list<Menu*> m_all_menus;

/** Used only for transition effects */
Menu* m_previous;

Menu* m_current;

friend class Menu;

public:
MenuManager();
~MenuManager();
Expand All @@ -59,13 +63,6 @@ class MenuManager
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&);
Expand Down

0 comments on commit 76262b7

Please sign in to comment.