From e724bdf483f485e299bdc12a8b5b19c6d43b76de 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 0298f519f7e..bf3cd89e0c7 100644 --- a/src/gui/core/event/handler.cpp +++ b/src/gui/core/event/handler.cpp @@ -1022,6 +1022,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 c0be440993c..d41794dab99 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 73f7cee5172..5edcbf93a12 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