From d37d1a03b20004cf014f8a9bd62b2545419603ad Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sun, 22 Oct 2023 19:38:54 +0400 Subject: [PATCH] On Windows, fix deadlock during `Cursor{Enter,Leave}` The lock was not released when calling back to the user. Fixes #3171. --- CHANGELOG.md | 2 ++ src/platform_impl/windows/event_loop.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e0a6c3424..53caaba58d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ Unreleased` header. # Unreleased +- On Windows, fix deadlock when accessing the state during `Cursor{Enter,Leave}`. + # 0.29.2 - **Breaking:** Bump MSRV from `1.60` to `1.65`. diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 59e5c9d5de..14080e8bc0 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1465,6 +1465,7 @@ unsafe fn public_window_callback_inner( .set_cursor_flags(window, |f| f.set(CursorFlags::IN_WINDOW, true)) .ok(); + drop(w); userdata.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), event: CursorEntered { @@ -1487,6 +1488,7 @@ unsafe fn public_window_callback_inner( .set_cursor_flags(window, |f| f.set(CursorFlags::IN_WINDOW, false)) .ok(); + drop(w); userdata.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), event: CursorLeft { @@ -1500,6 +1502,7 @@ unsafe fn public_window_callback_inner( // handle spurious WM_MOUSEMOVE messages // see https://devblogs.microsoft.com/oldnewthing/20031001-00/?p=42343 // and http://debugandconquer.blogspot.com/2015/08/the-cause-of-spurious-mouse-move.html + let mut w = userdata.window_state_lock(); cursor_moved = w.mouse.last_position != Some(position); w.mouse.last_position = Some(position); }