mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-18 17:28:13 +00:00
Make sure SDL_CaptureMouse() is only called on the main thread
Windows handles mouse capture on a per-thread basis, and capture must be done on the thread used to create a window. Fixes https://github.com/libsdl-org/SDL/issues/5577
This commit is contained in:
@@ -1069,6 +1069,17 @@ SDL_CaptureMouse(SDL_bool enabled)
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
/* Windows mouse capture is tied to the current thread, and must be called
|
||||
* from the thread that created the window being captured. Since we update
|
||||
* the mouse capture state from the event processing, any application state
|
||||
* changes must be processed on that thread as well.
|
||||
*/
|
||||
if (!SDL_OnVideoThread()) {
|
||||
return SDL_SetError("SDL_CaptureMouse() must be called on the main thread");
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
if (enabled && SDL_GetKeyboardFocus() == NULL) {
|
||||
return SDL_SetError("No window has focus");
|
||||
}
|
||||
|
Reference in New Issue
Block a user