Skip to content

Commit 0512502

Browse files
authored
On Windows, fix deadlock caused by mouse capture (rust-windowing#1830)
The issue was caused by calling SetCapture on a window which already had the capture. The WM_CAPTURECHANGED handler assumed that it would only run if the capture was lost, but that wasn't the case. This made the handler to try to lock the window state mutex while it was already locked. The issue was introduced in rust-windowing#1797 (932cbe4).
1 parent 05fe983 commit 0512502

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/platform_impl/windows/event_loop.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,13 @@ unsafe fn public_window_callback_inner<T: 'static>(
13941394
}
13951395

13961396
winuser::WM_CAPTURECHANGED => {
1397-
// window lost mouse capture
1398-
subclass_input.window_state.lock().mouse.capture_count = 0;
1397+
// lparam here is a handle to the window which is gaining mouse capture.
1398+
// If it is the same as our window, then we're essentially retaining the capture. This
1399+
// can happen if `SetCapture` is called on our window when it already has the mouse
1400+
// capture.
1401+
if lparam != window as isize {
1402+
subclass_input.window_state.lock().mouse.capture_count = 0;
1403+
}
13991404
0
14001405
}
14011406

0 commit comments

Comments
 (0)