From f0b2f6c3cd1317310a75772d28c02f2a65f42a21 Mon Sep 17 00:00:00 2001 From: Hilderin <81109165+Hilderin@users.noreply.github.com> Date: Thu, 6 Feb 2025 17:05:06 -0500 Subject: [PATCH] Fix error when embedded window is closed while resizing (cherry picked from commit b61499353f23ff41d6e8958dc2324388e607df40) --- scene/main/viewport.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index f7fd1a2c5a7..0098f4dc92a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -317,7 +317,13 @@ void Viewport::_sub_window_register(Window *p_window) { void Viewport::_sub_window_update(Window *p_window) { int index = _sub_window_find(p_window); - ERR_FAIL_COND(index == -1); + + // _sub_window_update is sometimes called deferred, and the window may have been closed since then. + // For example, when the user resizes the game window. + // In that case, _sub_window_find will not find it, which is expected. + if (index == -1) { + return; + } SubWindow &sw = gui.sub_windows.write[index]; sw.pending_window_update = false;