Bug in SDLJoystick.cpp?
#1
I found that my Xbox 360 wireless controller did not work after it had shut down---either when caused by me not using it or when disconnecting the batteries.

When everything worked, the log would output the following messages:

Code:
[...] DEBUG: Joystick 0 button 2 Down
[...]
[...] DEBUG: Joystick 0 button 2 Up

When dosconnected, the output would be:
Code:
[...] DEBUG: Joystick 4 button 2 Down
[...]
[...] DEBUG: Joystick 0 button 2 Up

I would not be able to control the interface anymore.

Luckily I compile XBMC from source, and was able to take a look at guilib/common/SDLJoystick.cpp. I noticed that the joystick identifier is taken from j, the array index. I presume that the joystick gets a different index in the list when it is reconnected.

SDL_JoystickIndex appears to consistently return the same identifiers.


Code:
Index: guilib/common/SDLJoystick.cpp
===================================================================
--- guilib/common/SDLJoystick.cpp    (revision 34876)
+++ guilib/common/SDLJoystick.cpp    (arbetskopia)
@@ -148,7 +148,7 @@
     {
       if (SDL_JoystickGetButton(joy, b))
       {
-        m_JoyId = j;
+        m_JoyId = SDL_JoystickIndex(joy);
         buttonId = b+1;
         j = numj-1;
         break;
@@ -160,7 +160,7 @@
       hatval = SDL_JoystickGetHat(joy, h);
       if (hatval != SDL_HAT_CENTERED)
       {
-        m_JoyId = j;
+        m_JoyId = SDL_JoystickIndex(joy);
         hatId = h + 1;
         m_HatState = hatval;
         j = numj-1;
@@ -186,7 +186,7 @@
     m_AxisId = GetAxisWithMaxAmount();
     if (m_AxisId)
     {
-      m_JoyId = j;
+      m_JoyId = SDL_JoystickIndex(joy);
       j = numj-1;
       break;
     }
Reply
#2
definitely looks correct
Reply

Logout Mark Read Team Forum Stats Members Help
Bug in SDLJoystick.cpp?0