mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-07 10:22:02 +00:00
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:
parent
fd7877c26c
commit
e724bdf483
@ -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();
|
||||
|
@ -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?
|
||||
*
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user