mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-30 23:18:29 +00:00
Revamped joystick locking
This makes the joystick locking more robust by holding the lock while updating joysticks. The lock should be held when calling any SDL joystick function on a different thread than the one calling SDL_PumpEvents() and SDL_JoystickUpdate(). It is now possible to hold the lock while reinitializing the joystick subsystem, however any open joysticks will become invalid and potentially cause crashes if used afterwards. Fixes https://github.com/libsdl-org/SDL/issues/6063
This commit is contained in:
@@ -253,9 +253,11 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
HRESULT hr;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController *controller = NULL;
|
||||
|
||||
/* We can get delayed calls to InvokeAdded() after WGI_JoystickQuit(). Do nothing if WGI is deinitialized.
|
||||
* FIXME: Can we tell if WGI has been quit and reinitialized prior to a delayed callback? */
|
||||
if (wgi.statics == NULL) {
|
||||
SDL_LockJoysticks();
|
||||
|
||||
/* We can get delayed calls to InvokeAdded() after WGI_JoystickQuit() */
|
||||
if (SDL_JoysticksQuitting() || !SDL_JoysticksInitialized()) {
|
||||
SDL_UnlockJoysticks();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -388,6 +390,9 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController_Release(controller);
|
||||
}
|
||||
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user