More verbosity and error checking.
authorEdgar Simo <bobbens@gmail.com>
Sat, 21 Feb 2009 18:03:22 +0000
changeset 30804094b4f1c3a1
parent 3079 cfc8b35ad6b1
child 3081 4ccdf20bad6f
More verbosity and error checking.
src/haptic/SDL_haptic.c
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/src/haptic/SDL_haptic.c	Sat Feb 21 18:02:55 2009 +0000
     1.2 +++ b/src/haptic/SDL_haptic.c	Sat Feb 21 18:03:22 2009 +0000
     1.3 @@ -66,13 +66,20 @@
     1.4      int valid;
     1.5  
     1.6      valid = 0;
     1.7 -    for (i = 0; i < SDL_numhaptics; i++) {
     1.8 -        if (SDL_haptics[i] == haptic) {
     1.9 -            valid = 1;
    1.10 -            break;
    1.11 +    if (haptic != NULL) {
    1.12 +        for (i = 0; i < SDL_numhaptics; i++) {
    1.13 +            if (SDL_haptics[i] == haptic) {
    1.14 +                valid = 1;
    1.15 +                break;
    1.16 +            }
    1.17          }
    1.18      }
    1.19  
    1.20 +    /* Create the error here. */
    1.21 +    if (valid == 0) {
    1.22 +        SDL_SetError("Haptic: Invalid haptic device identifier");
    1.23 +    }
    1.24 +
    1.25      return valid;
    1.26  }
    1.27  
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sat Feb 21 18:02:55 2009 +0000
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sat Feb 21 18:03:22 2009 +0000
     2.3 @@ -395,17 +395,28 @@
     2.4      int fd;
     2.5      int ret;
     2.6  
     2.7 +
     2.8      /* Find the joystick in the haptic list. */
     2.9      for (i = 0; i < MAX_HAPTICS; i++) {
    2.10          if (SDL_hapticlist[i].fname != NULL) {
    2.11              if (SDL_strcmp(SDL_hapticlist[i].fname, joystick->hwdata->fname)
    2.12                  == 0) {
    2.13                  haptic->index = i;
    2.14 +                break;
    2.15              }
    2.16          }
    2.17      }
    2.18 +    if (i >= MAX_HAPTICS) {
    2.19 +        SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
    2.20 +        return -1;
    2.21 +    }
    2.22  
    2.23      fd = open(joystick->hwdata->fname, O_RDWR, 0);
    2.24 +    if (fd < 0) {
    2.25 +        SDL_SetError("Haptic: Unable to open %s: %s",
    2.26 +                     joystick->hwdata->fname, strerror(errno));
    2.27 +        return -1;
    2.28 +    }
    2.29      ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
    2.30      if (ret < 0) {
    2.31          return -1;