src/joystick/windows/SDL_dxjoystick.c
changeset 5090 327f181542f1
parent 5062 e8916fe9cfc8
child 5262 b530ef003506
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Mon Jan 24 17:47:18 2011 -0800
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Jan 24 21:20:30 2011 -0800
     1.3 @@ -63,6 +63,7 @@
     1.4                                         LPDIRECTINPUT * ppDI,
     1.5                                         LPUNKNOWN punkOuter);
     1.6  static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS];    /* array to hold joystick ID values */
     1.7 +static char *SYS_JoystickNames[MAX_JOYSTICKS];
     1.8  static int SYS_NumJoysticks;
     1.9  static HINSTANCE DInputDLL = NULL;
    1.10  
    1.11 @@ -326,6 +327,7 @@
    1.12  {
    1.13      SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
    1.14                 sizeof(DIDEVICEINSTANCE));
    1.15 +    SYS_JoystickNames[SYS_NumJoysticks] = WIN_StringToUTF8(pdidInstance->tszProductName);
    1.16      SYS_NumJoysticks++;
    1.17  
    1.18      if (SYS_NumJoysticks >= MAX_JOYSTICKS)
    1.19 @@ -338,8 +340,7 @@
    1.20  const char *
    1.21  SDL_SYS_JoystickName(int index)
    1.22  {
    1.23 -        /***-> test for invalid index ? */
    1.24 -    return (SYS_Joystick[index].tszProductName);
    1.25 +    return SYS_JoystickNames[index];
    1.26  }
    1.27  
    1.28  /* Function to open a joystick for use.
    1.29 @@ -793,6 +794,15 @@
    1.30  void
    1.31  SDL_SYS_JoystickQuit(void)
    1.32  {
    1.33 +    int i;
    1.34 +
    1.35 +    for (i = 0; i < SDL_arraysize(SYS_JoystickNames); ++i) {
    1.36 +        if (SYS_JoystickNames[i]) {
    1.37 +            SDL_free(SYS_JoystickNames[i]);
    1.38 +            SYS_JoystickNames[i] = NULL;
    1.39 +        }
    1.40 +    }
    1.41 +
    1.42      IDirectInput_Release(dinput);
    1.43      dinput = NULL;
    1.44  }