From e2cea458a34665c03d57aa52bddcfd8054d3bf03 Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Sat, 19 Aug 2023 11:20:38 +0200 Subject: [PATCH] Fix crash when hiding subwindow during popup of new subwindow --- scene/main/viewport.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 2d3aa66f2cd..e82db2abb64 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -363,6 +363,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); @@ -374,6 +375,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); @@ -401,6 +404,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);