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.
This commit is contained in:
Charles Dang 2017-07-29 23:16:21 +11:00
parent fd7877c26c
commit e724bdf483
3 changed files with 14 additions and 1 deletions

View File

@ -1022,6 +1022,16 @@ std::ostream& operator<<(std::ostream& stream, const ui_event event)
std::vector<window*> 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();

View File

@ -297,6 +297,9 @@ std::ostream& operator<<(std::ostream& stream, const ui_event event);
*/
extern std::vector<window*> 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?
*

View File

@ -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