Fixed crash on Windows if haptic isn't initialized when controllers are added.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 06 Feb 2014 21:26:41 -0500
changeset 8185 c2996dc8ef6b
parent 8184 2afb90ff0199
child 8186 a3b4d7e5eb8e
Fixed crash on Windows if haptic isn't initialized when controllers are added.
src/haptic/windows/SDL_syshaptic.c
--- a/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 10:00:45 2014 -0500
+++ b/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 21:26:41 2014 -0500
@@ -221,6 +221,10 @@
     DIDEVCAPS capabilities;
     SDL_hapticlist_item *item = NULL;
 
+    if (dinput == NULL) {
+        return -1;  /* not initialized. We'll pick these up on enumeration if we init later. */
+    }
+
     /* Make sure we don't already have it */
     for (item = SDL_hapticlist; item; item = item->next) {
         if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) {
@@ -286,6 +290,10 @@
     SDL_hapticlist_item *item;
     SDL_hapticlist_item *prev = NULL;
 
+    if (dinput == NULL) {
+        return -1;  /* not initialized, ignore this. */
+    }
+
     for (item = SDL_hapticlist; item != NULL; item = item->next) {
         if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) {
             /* found it, remove it. */