From 2ef8b1a76f730e38d7faa793492d8235798a69dd Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Sat, 14 Feb 2015 15:22:04 +0100 Subject: [PATCH] Emscripten: Fixed sending SDL_JOYDEVICEADDED events with an index out of range. SDL_JOYDEVICEADDED events must contain the device index which is a value between 0 and the number of connected joysticks. The old implementation included a value based on the instance id instead. It worked in some cases because the values are similar initially. But after disconnecting joysticks this is no more the case and the always increasing instance id becomes larger than number of joysticks. --- src/joystick/emscripten/SDL_sysjoystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index 324338cbe..ded4b62b8 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -112,7 +112,7 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa event.type = SDL_JOYDEVICEADDED; if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = item->device_instance - 1; + event.jdevice.which = item->index; if ( (SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event) ) { SDL_PushEvent(&event);