Fixed bug 2833 - Access Violation on SDL_PollEvent after init, delay and quit of joystick subsystem
authorSam Lantinga
Fri, 07 Oct 2016 16:32:58 -0700
changeset 10479aa816d06ed78
parent 10478 30302a3c5df7
child 10480 145a5c94ede3
Fixed bug 2833 - Access Violation on SDL_PollEvent after init, delay and quit of joystick subsystem

Jan Klass

Not sure if this is limited to the joystick subsystem,
but I created a minimal program for reproducibility,
which is attached.

The issue occurs with my gamepad Razer Onza (an xbox-style gamepad) plugged in.
On initialization, the gamepad is being recognized.
After quitting the subsystem, the poll will receive the joystick added event,
which it instantly handles itself, calling SDL_SYS_JoystickDetect again,
which this time calls IDirectInput8_EnumDevices with dinput = NULL (after it was released on quit).
This seems to lead to an access violation within said function, which I have no source for.
src/joystick/windows/SDL_windowsjoystick.c
     1.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Fri Oct 07 16:19:50 2016 -0700
     1.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Fri Oct 07 16:32:58 2016 -0700
     1.3 @@ -509,6 +509,9 @@
     1.4  
     1.5      SDL_DINPUT_JoystickQuit();
     1.6      SDL_XINPUT_JoystickQuit();
     1.7 +
     1.8 +    s_bDeviceAdded = SDL_FALSE;
     1.9 +    s_bDeviceRemoved = SDL_FALSE;
    1.10  }
    1.11  
    1.12  /* return the stable device guid for this device index */