From bbf63466e877c9b57bc708e52f9ffdec61e65db1 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sat, 29 Jul 2017 23:16:21 +1100 Subject: [PATCH] GUI2/Modal Dialog: don't use pop_back to remove window ptr from open window stack This seems to have been the cause of some crashes and weird behavior with the new command console. Likely the problem came from the wrong pointer being removed from the ows, but exactly why a modal dialog was even being opened I don't know. Still, this is a safer method overall and it guarantees the correct pointer is always removed. --- src/gui/core/event/handler.cpp | 10 ++++++++++ src/gui/core/event/handler.hpp | 3 +++ src/gui/dialogs/modal_dialog.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/core/event/handler.cpp b/src/gui/core/event/handler.cpp index 995ad28078b39..15b1857f9be74 100644 --- a/src/gui/core/event/handler.cpp +++ b/src/gui/core/event/handler.cpp @@ -943,6 +943,16 @@ std::ostream& operator<<(std::ostream& stream, const ui_event event) std::vector open_window_stack {}; +void remove_from_window_stack(window* window) +{ + for(auto iter = open_window_stack.rbegin(); iter != open_window_stack.rend(); ++iter) { + if(*iter == window) { + open_window_stack.erase(std::next(iter).base()); + break; + } + } +} + bool is_in_dialog() { return !open_window_stack.empty(); diff --git a/src/gui/core/event/handler.hpp b/src/gui/core/event/handler.hpp index c0be440993c28..d41794dab997b 100644 --- a/src/gui/core/event/handler.hpp +++ b/src/gui/core/event/handler.hpp @@ -297,6 +297,9 @@ std::ostream& operator<<(std::ostream& stream, const ui_event event); */ extern std::vector open_window_stack; +/** Removes a entry from the open_window_stack list. This should be used instead of pop_back. */ +void remove_from_window_stack(window* window); + /** * Is a dialog open? * diff --git a/src/gui/dialogs/modal_dialog.cpp b/src/gui/dialogs/modal_dialog.cpp index 73f7cee517250..5edcbf93a1270 100644 --- a/src/gui/dialogs/modal_dialog.cpp +++ b/src/gui/dialogs/modal_dialog.cpp @@ -69,7 +69,7 @@ bool modal_dialog::show(CVideo& video, const unsigned auto_close_time) retval_ = window->show(restore_, auto_close_time); - open_window_stack.pop_back(); + remove_from_window_stack(window.get()); /* * It can happen that when two clicks follow each other fast that the event