# HG changeset patch # User Edgar Simo # Date 1235239402 0 # Node ID 4094b4f1c3a1c08a3ae59f5fc1e7ae2974a626ef # Parent cfc8b35ad6b1a86faa99cca37cb29dce98d42415 More verbosity and error checking. diff -r cfc8b35ad6b1 -r 4094b4f1c3a1 src/haptic/SDL_haptic.c --- a/src/haptic/SDL_haptic.c Sat Feb 21 18:02:55 2009 +0000 +++ b/src/haptic/SDL_haptic.c Sat Feb 21 18:03:22 2009 +0000 @@ -66,13 +66,20 @@ int valid; valid = 0; - for (i = 0; i < SDL_numhaptics; i++) { - if (SDL_haptics[i] == haptic) { - valid = 1; - break; + if (haptic != NULL) { + for (i = 0; i < SDL_numhaptics; i++) { + if (SDL_haptics[i] == haptic) { + valid = 1; + break; + } } } + /* Create the error here. */ + if (valid == 0) { + SDL_SetError("Haptic: Invalid haptic device identifier"); + } + return valid; } diff -r cfc8b35ad6b1 -r 4094b4f1c3a1 src/haptic/linux/SDL_syshaptic.c --- a/src/haptic/linux/SDL_syshaptic.c Sat Feb 21 18:02:55 2009 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Sat Feb 21 18:03:22 2009 +0000 @@ -395,17 +395,28 @@ int fd; int ret; + /* Find the joystick in the haptic list. */ for (i = 0; i < MAX_HAPTICS; i++) { if (SDL_hapticlist[i].fname != NULL) { if (SDL_strcmp(SDL_hapticlist[i].fname, joystick->hwdata->fname) == 0) { haptic->index = i; + break; } } } + if (i >= MAX_HAPTICS) { + SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities"); + return -1; + } fd = open(joystick->hwdata->fname, O_RDWR, 0); + if (fd < 0) { + SDL_SetError("Haptic: Unable to open %s: %s", + joystick->hwdata->fname, strerror(errno)); + return -1; + } ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */ if (ret < 0) { return -1;