From: Ingo Ruhnke Date: Tue, 26 Aug 2014 07:03:24 +0000 (+0200) Subject: Implemented delayed destruction of Dialog in MenuManager to avoid "delete this" type... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9f727419032add53276c2f86dc987cf04441c5f3;p=supertux.git Implemented delayed destruction of Dialog in MenuManager to avoid "delete this" type problems --- diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index b493ba651..a3c4b8e26 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -136,6 +136,8 @@ public: MenuManager::MenuManager() : m_dialog(), + m_has_next_dialog(false), + m_next_dialog(), m_menu_stack(), m_transition(new MenuTransition) { @@ -190,6 +192,12 @@ MenuManager::event(const SDL_Event& ev) void MenuManager::draw(DrawingContext& context) { + if (m_has_next_dialog) + { + m_dialog = std::move(m_next_dialog); + m_has_next_dialog = false; + } + if (m_transition->is_active()) { m_transition->update(); @@ -222,7 +230,10 @@ MenuManager::draw(DrawingContext& context) void MenuManager::set_dialog(std::unique_ptr dialog) { - m_dialog = std::move(dialog); + // delay reseting m_dialog to a later point, as otherwise the Dialog + // can't unset itself without ending up with "delete this" problems + m_next_dialog = std::move(dialog); + m_has_next_dialog = true; } void diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp index e05a083ae..2be698318 100644 --- a/src/gui/menu_manager.hpp +++ b/src/gui/menu_manager.hpp @@ -17,9 +17,9 @@ #ifndef HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP #define HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP -#include #include #include +#include #include "SDL.h" @@ -37,6 +37,9 @@ public: private: std::unique_ptr m_dialog; + bool m_has_next_dialog; + std::unique_ptr m_next_dialog; + std::vector > m_menu_stack; std::unique_ptr m_transition;