Skip to content

Commit

Permalink
GUI2/Modal Dialog: don't use pop_back to remove window ptr from open …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Vultraz committed Jul 30, 2017
1 parent fd7877c commit e724bdf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/gui/core/event/handler.cpp
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/core/event/handler.hpp
Expand Up @@ -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?
*
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/modal_dialog.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e724bdf

Please sign in to comment.