Corrected Linux joystick things, fixes assertion failure from testjoystick.
authorRyan C. Gordon
Thu, 13 Dec 2012 22:26:30 -0500
changeset 67528de11011eb1f
parent 6751 a1f87fd7ed72
child 6753 332c36fd0fd7
Corrected Linux joystick things, fixes assertion failure from testjoystick.
src/joystick/linux/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick_c.h
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Dec 13 22:18:32 2012 -0500
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Dec 13 22:26:30 2012 -0500
     1.3 @@ -319,7 +319,7 @@
     1.4          if (SDL_strcmp(path, item->path) == 0) {
     1.5              const int retval = item->device_instance;
     1.6              if (item->hwdata) {
     1.7 -                item->hwdata->removed = SDL_TRUE;
     1.8 +                item->hwdata->item = NULL;
     1.9              }
    1.10              if (prev != NULL) {
    1.11                  prev->next = item->next;
    1.12 @@ -731,7 +731,7 @@
    1.13          return (-1);
    1.14      }
    1.15      SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
    1.16 -    joystick->hwdata->removed = SDL_FALSE;
    1.17 +    joystick->hwdata->item = item;
    1.18      joystick->hwdata->guid = item->guid;
    1.19      joystick->hwdata->fd = fd;
    1.20      joystick->hwdata->fname = SDL_strdup(item->path);
    1.21 @@ -758,7 +758,7 @@
    1.22  /* Function to determine is this joystick is attached to the system right now */
    1.23  SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    1.24  {
    1.25 -    return !joystick->closed && !joystick->hwdata->removed;
    1.26 +    return !joystick->closed && (joystick->hwdata->item != NULL);
    1.27  }
    1.28  
    1.29  static __inline__ void
    1.30 @@ -913,6 +913,9 @@
    1.31  {
    1.32      if (joystick->hwdata) {
    1.33          close(joystick->hwdata->fd);
    1.34 +        if (joystick->hwdata->item) {
    1.35 +            joystick->hwdata->item->hwdata = NULL;
    1.36 +        }
    1.37          SDL_free(joystick->hwdata->hats);
    1.38          SDL_free(joystick->hwdata->balls);
    1.39          SDL_free(joystick->hwdata->fname);
     2.1 --- a/src/joystick/linux/SDL_sysjoystick_c.h	Thu Dec 13 22:18:32 2012 -0500
     2.2 +++ b/src/joystick/linux/SDL_sysjoystick_c.h	Thu Dec 13 22:26:30 2012 -0500
     2.3 @@ -21,12 +21,13 @@
     2.4  
     2.5  #include <linux/input.h>
     2.6  
     2.7 +struct SDL_joylist_item;
     2.8 +
     2.9  /* The private structure used to keep track of a joystick */
    2.10  struct joystick_hwdata
    2.11  {
    2.12      int fd;
    2.13 -    SDL_bool removed;
    2.14 -
    2.15 +    struct SDL_joylist_item *item;
    2.16      SDL_JoystickGUID guid;
    2.17      char *fname;                /* Used in haptic subsystem */
    2.18