Skip to content

Commit

Permalink
Fix race condition that can lead to ENTER/LEAVE window events never f…
Browse files Browse the repository at this point in the history
…iring

On windows, when toggling the state of RelativeMode rapidly, there is a
high chance that SDL_WINDOWEVENT_ENTER / SDL_WINDOWEVENT_LEAVE events
will stop firing indefinitely.

This aims to resolve that shortcoming by ensuring mouse focus state is
correctly updated via WM_MOUSELEAVE events arriving via the windows
event hook.
  • Loading branch information
peppy authored and slouken committed Apr 7, 2021
1 parent 4cee101 commit 89b6209
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video/windows/SDL_windowsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
}
SDL_SetMouseFocus(NULL);
}

/* When WM_MOUSELEAVE is fired we can be assured that the cursor has left the window.
Regardless of relative mode, it is important that mouse focus is reset as there is a potential
race condition when in the process of leaving/entering relative mode, resulting in focus never
being lost. This then causes a cascading failure where SDL_WINDOWEVENT_ENTER / SDL_WINDOWEVENT_LEAVE
can stop firing permanently, due to the focus being in the wrong state and TrackMouseEvent never
resubscribing. */
SDL_SetMouseFocus(NULL);

returnCode = 0;
break;
#endif /* WM_MOUSELEAVE */
Expand Down

0 comments on commit 89b6209

Please sign in to comment.