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:
Sam Lantinga
2022-08-30 11:42:13 -07:00
parent ff233fe306
commit 40bd4feedc
5 changed files with 138 additions and 115 deletions

View File

@@ -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;
}