Fixed bug 5327 - When direct input fails to load, but a controlller is plugged in through another api, an access violation happens.

Bart van der Werf

When directinput fails to load, but a controlller is plugged in, an access violation happens.
This is due to IEventHandler_CRawGameControllerVtbl_InvokeAdded calling SDL_DINPUT_JoystickPresent which does not check if dinput is assigned signalling initialization of directinput.
This commit is contained in:
Sam Lantinga 2020-11-11 19:43:02 -08:00
parent 502cfe314a
commit 3160c7d66f
1 changed files with 9 additions and 0 deletions

View File

@ -514,11 +514,15 @@ SDL_DINPUT_JoystickInit(void)
/* Because we used CoCreateInstance, we need to Initialize it, first. */
instance = GetModuleHandle(NULL);
if (instance == NULL) {
IDirectInput8_Release(dinput);
dinput = NULL;
return SDL_SetError("GetModuleHandle() failed with error code %lu.", GetLastError());
}
result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
if (FAILED(result)) {
IDirectInput8_Release(dinput);
dinput = NULL;
return SetDIerror("IDirectInput::Initialize", result);
}
return 0;
@ -724,6 +728,11 @@ EnumJoystickPresentCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pConte
SDL_bool
SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version)
{
if (dinput == NULL)
{
return SDL_FALSE;
}
EnumJoystickPresentData data;
data.vendor = vendor;