ignore hot plugs in mac haptic layer IF hap tics hasn't been initialized.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index 306eda9..4a62e35 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -85,7 +85,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name);
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 @@ SDL_SYS_HapticInit(void)
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 @@ MacHaptic_MaybeAddDevice( io_object_t device )
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 @@ MacHaptic_MaybeRemoveDevice( io_object_t device )
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 @@ SDL_SYS_HapticQuit(void)
IOObjectRelease(item->dev);
SDL_free(item);
}
- numhaptics = 0;
+ numhaptics = -1;
}