Skip to content

Commit

Permalink
Merge pull request #80780 from HolonProduction/sub-window-focus-crash
Browse files Browse the repository at this point in the history
Fix crash when hiding subwindow during popup of new subwindow
  • Loading branch information
akien-mga committed Aug 21, 2023
2 parents a723a8d + e2cea45 commit b24eb34
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void Viewport::_sub_window_grab_focus(Window *p_window) {
return;
}

// The index needs to be update before every usage in case an event callback changed the window list.
int index = _sub_window_find(p_window);
ERR_FAIL_COND(index == -1);

Expand All @@ -379,6 +380,8 @@ void Viewport::_sub_window_grab_focus(Window *p_window) {
gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
}
// Can only move to foreground, but no focus granted.
index = _sub_window_find(p_window);
ERR_FAIL_COND(index == -1);
SubWindow sw = gui.sub_windows[index];
gui.sub_windows.remove_at(index);
gui.sub_windows.push_back(sw);
Expand Down Expand Up @@ -406,6 +409,8 @@ void Viewport::_sub_window_grab_focus(Window *p_window) {
gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_IN);

{ // Move to foreground.
index = _sub_window_find(p_window);
ERR_FAIL_COND(index == -1);
SubWindow sw = gui.sub_windows[index];
gui.sub_windows.remove_at(index);
gui.sub_windows.push_back(sw);
Expand Down

0 comments on commit b24eb34

Please sign in to comment.