src/joystick/darwin/SDL_sysjoystick.c
branchgsoc2008_force_feedback
changeset 2637 2f826c229d77
parent 2632 9e7f58b1b255
child 2638 db93456d4b26
--- a/src/joystick/darwin/SDL_sysjoystick.c	Wed Aug 06 17:14:54 2008 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sun Aug 10 19:45:38 2008 +0000
@@ -545,6 +545,12 @@
         /* save next device prior to disposing of this device */
         pDeviceNext = (*ppDevice)->pNext;
 
+        /* free posible io_service_t */
+        if ((*ppDevice)->ffservice) {
+            IOObjectRelease((*ppDevice)->ffservice);
+            (*ppDevice)->ffservice = 0;
+        }
+
         /* free element lists */
         HIDDisposeElementList(&(*ppDevice)->firstAxis);
         HIDDisposeElementList(&(*ppDevice)->firstButton);
@@ -637,8 +643,16 @@
         if (!device)
             continue;
 
-        /* dump device object, it is no longer needed */
-        result = IOObjectRelease(ioHIDDeviceObject);
+        /* We have to do some storage of the io_service_t for
+         * SDL_HapticOpenFromJoystick */
+        if (FFIsForceFeedback(device) == FF_OK) {
+           device->ffservice = ioHIDDeviceObject;
+        }
+        else {
+           device->ffservice = 0;
+           /* dump device object, it is no longer needed */
+           result = IOObjectRelease(ioHIDDeviceObject);
+        }
 /*		if (KERN_SUCCESS != result)
 			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
 */