If I call SDL_Init() with SDL_INIT_JOYSTICK, and I already have a game controller plugged in, it crashes for me.
If no controller is plugged in, the SDL app runs fine. If a controller gets plugged in after it’s already started, it crashes in the same area.
(Note: my XBox 360 controller isn’t crashing - it functions fine. The non-XInput controllers are crashing).
I’m compiling SDL 2.0.7 (stable) with MinGW 5.3.0 (MinGW-W64) on Windows 10.
I’m linking against: -lmingw32 -lSDL2main -lSDL2 (are there any I’m missing?)
(Note this is just a test project to get it working. It’s just: http://lazyfoo.net/tutorials/SDL/20_force_feedback/index.php
with a few minor changes (i.e. removing SDL_image and using SDL_LoadBMP instead).
The debugger is telling me it crashes in SDL_dinputjoystick.c, in EnumJoystickCallback, though I don’t know precisely where (the debugger says line number 397, but I think the last two stackframes are wrong… The secondmost stackframe doesn’t match up with the function name it’s supposedly in).
The callstack is:
1 EnumJoysticksCallback SDL_dinputjoystick.c 397 0x6834293f
2 EnumJoysticksCallback SDL_dinputjoystick.c 295 0x68342cd3
3 ?? 0x719345b5
4 SDL_DINPUT_JoystickDetect SDL_dinputjoystick.c 483 0x68342f30
5 SDL_SYS_JoystickDetect SDL_windowsjoystick.c 349 0x68343a95
6 SDL_SYS_JoystickInit SDL_windowsjoystick.c 305 0x68343e9c
7 SDL_JoystickInit SDL_joystick.c 91 0x6832bd22
8 SDL_InitSubSystem_REAL SDL.c 198 0x68281935
9 SDL_Init_REAL SDL.c 241 0x68281935
10 init main.cpp 238 0x401939
11 SDL_main main.cpp 358 0x401c26
12 main_utf8 SDL_windows_main.c 126 0x402fb9
13 main_getcmdline SDL_windows_main.c 159 0x402fb9
14 WinMain *16 SDL_windows_main.c 202 0x4031a8
15 main 0x40346d
I’m not sure if it’s relevant or not, but SDL_SYS_JoystickDetect() in SDL_windowsjoystick.c passes a null pointer to SDL_DINPUT_JoystickDetect(), so EnumJoysticksCallback()'s ‘pContext’ is also null.
I’ve tried with two different DirectInput gamepads (a non-XInput Logitech and a PS4 controller) - both crash it. The Xbox 360 controller doesn’t crash, however, and works fine, being XInput.