ignore hot plugs in mac haptic layer IF hap tics hasn't been initialized.
authorEdward Rudd <urkle@outoforder.cc>
Fri, 07 Feb 2014 09:35:13 -0500
changeset 8187 432f5c06b43e
parent 8186 a3b4d7e5eb8e
child 8188 47b9ab82bebf
ignore hot plugs in mac haptic layer IF hap tics hasn't been initialized.
src/haptic/darwin/SDL_syshaptic.c
--- a/src/haptic/darwin/SDL_syshaptic.c	Thu Feb 06 21:28:11 2014 -0500
+++ b/src/haptic/darwin/SDL_syshaptic.c	Fri Feb 07 09:35:13 2014 -0500
@@ -85,7 +85,7 @@
 
 static SDL_hapticlist_item *SDL_hapticlist = NULL;
 static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
-static int numhaptics = 0;
+static int numhaptics = -1;
 
 /*
  * Like strerror but for force feedback errors.
@@ -155,6 +155,11 @@
     CFDictionaryRef match;
     io_service_t device;
 
+    if (numhaptics != -1) {
+        return SDL_Error("Haptic subsystem already initialized!");
+    }
+    numhaptics = 0;
+
     /* Get HID devices. */
     match = IOServiceMatching(kIOHIDDeviceKey);
     if (match == NULL) {
@@ -214,6 +219,10 @@
     CFTypeRef refCF;
     SDL_hapticlist_item *item;
 
+    if (numhaptics == -1) {
+        return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
+    }
+
     /* Check for force feedback. */
     if (FFIsForceFeedback(device) != FF_OK) {
         return -1;
@@ -288,6 +297,10 @@
     SDL_hapticlist_item *item;
     SDL_hapticlist_item *prev = NULL;
 
+    if (numhaptics == -1) {
+        return -1; /* not initialized. ignore this. */
+    }
+
     for (item = SDL_hapticlist; item != NULL; item = item->next) {
         /* found it, remove it. */
         if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
@@ -674,7 +687,7 @@
         IOObjectRelease(item->dev);
         SDL_free(item);
     }
-    numhaptics = 0;
+    numhaptics = -1;
 }