From 4690a091e3152771c163f0c415cbbac39b369eca Mon Sep 17 00:00:00 2001 From: Jacob Walser Date: Wed, 19 Jul 2017 17:57:37 -0400 Subject: [PATCH 1/2] Joystick: give duplicate joystick names distinct keys --- src/Joystick/JoystickSDL.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Joystick/JoystickSDL.cc b/src/Joystick/JoystickSDL.cc index 3a230e4ab25..915d4c47fd4 100644 --- a/src/Joystick/JoystickSDL.cc +++ b/src/Joystick/JoystickSDL.cc @@ -36,7 +36,6 @@ QMap JoystickSDL::discover(MultiVehicleManager* _multiVehicl for (int i=0; i JoystickSDL::discover(MultiVehicleManager* _multiVehicl } qCDebug(JoystickLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount << "hats:" << hatCount << "isGC:" << isGameController; + + // Check for joysticks with duplicate names and differentiate the keys when neccessary. + // This is required when using an Xbox 360 wireless receiver that always identifies as + // 4 individual joysticks, regardless of how many joysticks are actually connected to the + // receiver. Using GUID does not help, all of these devices present the same GUID. + QString originalName = name; + uint8_t duplicateIdx = 1; + while (newRet[name]) { + name = QString("%1 %2").arg(originalName).arg(duplicateIdx++); + } + newRet[name] = new JoystickSDL(name, qMax(0,axisCount), qMax(0,buttonCount), qMax(0,hatCount), i, isGameController, _multiVehicleManager); } else { newRet[name] = ret[name]; From 63a342c4dc7397640611ed382a7e33efcb5d7080 Mon Sep 17 00:00:00 2001 From: Jacob Walser Date: Wed, 19 Jul 2017 17:58:40 -0400 Subject: [PATCH 2/2] Don't close joysticks --- src/Joystick/JoystickSDL.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Joystick/JoystickSDL.cc b/src/Joystick/JoystickSDL.cc index 915d4c47fd4..9e96eebfe5c 100644 --- a/src/Joystick/JoystickSDL.cc +++ b/src/Joystick/JoystickSDL.cc @@ -145,7 +145,10 @@ void JoystickSDL::_close(void) { if (SDL_JoystickInstanceID(sdlJoystick) != -1) { qCDebug(JoystickLog) << "\tID:" << SDL_JoystickInstanceID(sdlJoystick); - SDL_JoystickClose(sdlJoystick); + // This segfaults so often, and I've spent so much time trying to find the cause and fix it + // I think this might be an SDL bug + // We are much more stable just commenting this out + //SDL_JoystickClose(sdlJoystick); } }