From 8c1ce404d7d96c7034018a37cbf4a8bcad6d7386 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Wed, 2 Aug 2023 00:17:25 +0200 Subject: [PATCH] Fix crash on Windows when closing `Window` Send `WINDOW_EVENT_MOUSE_EXIT` when a window is destroyed. Ensure, that on Windows, the event_callback is still valid during destroying the `Window`. --- platform/linuxbsd/x11/display_server_x11.cpp | 6 ++++++ platform/windows/display_server_windows.cpp | 4 ++++ scene/main/window.cpp | 6 ------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 7189a1c1c9a..2643cd3b1ad 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -1449,6 +1449,12 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) { DEBUG_LOG_X11("delete_sub_window: %lu (%u) \n", wd.x11_window, p_id); + window_set_rect_changed_callback(Callable(), p_id); + window_set_window_event_callback(Callable(), p_id); + window_set_input_event_callback(Callable(), p_id); + window_set_input_text_callback(Callable(), p_id); + window_set_drop_files_callback(Callable(), p_id); + while (wd.transient_children.size()) { window_set_transient(*wd.transient_children.begin(), INVALID_WINDOW_ID); } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index c073d6f028c..e32b3770472 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -3838,6 +3838,10 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } break; case WM_DESTROY: { Input::get_singleton()->flush_buffered_events(); + if (window_mouseover_id == window_id) { + window_mouseover_id = INVALID_WINDOW_ID; + _send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT); + } } break; case WM_SETCURSOR: { if (LOWORD(lParam) == HTCLIENT) { diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 6182530431a..bd51f8eeaf0 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -618,12 +618,6 @@ void Window::_clear_window() { bool had_focus = has_focus(); - DisplayServer::get_singleton()->window_set_rect_changed_callback(Callable(), window_id); - DisplayServer::get_singleton()->window_set_window_event_callback(Callable(), window_id); - DisplayServer::get_singleton()->window_set_input_event_callback(Callable(), window_id); - DisplayServer::get_singleton()->window_set_input_text_callback(Callable(), window_id); - DisplayServer::get_singleton()->window_set_drop_files_callback(Callable(), window_id); - if (transient_parent && transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID); }