src/joystick/darwin/SDL_sysjoystick.c
changeset 13642 f4ae4b91cf38
parent 13638 ca87b62e4e17
child 13646 784ce9766fb9
equal deleted inserted replaced
13641:d0b788429c57 13642:f4ae4b91cf38
   123 
   123 
   124 static recDevice *
   124 static recDevice *
   125 FreeDevice(recDevice *removeDevice)
   125 FreeDevice(recDevice *removeDevice)
   126 {
   126 {
   127     recDevice *pDeviceNext = NULL;
   127     recDevice *pDeviceNext = NULL;
   128     SDL_Joystick *joystick = NULL;
       
   129     if (removeDevice) {
   128     if (removeDevice) {
   130         if (removeDevice->deviceRef) {
   129         if (removeDevice->deviceRef) {
   131             IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
   130             IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
   132             CFRelease(removeDevice->deviceRef);
   131             CFRelease(removeDevice->deviceRef);
   133             removeDevice->deviceRef = NULL;
   132             removeDevice->deviceRef = NULL;
   144                 device = device->pNext;
   143                 device = device->pNext;
   145             }
   144             }
   146             device->pNext = pDeviceNext;
   145             device->pNext = pDeviceNext;
   147         }
   146         }
   148         removeDevice->pNext = NULL;
   147         removeDevice->pNext = NULL;
   149 
       
   150         /* clear out any reference to this recDevice that are being
       
   151          * held by a live instance of SDL_Joystick
       
   152          */
       
   153         joystick = SDL_JoystickFromInstanceID(removeDevice->instance_id);
       
   154         if (joystick) {
       
   155             joystick->hwdata = NULL;
       
   156         }
       
   157 
   148 
   158         /* free element lists */
   149         /* free element lists */
   159         FreeElementList(removeDevice->firstAxis);
   150         FreeElementList(removeDevice->firstAxis);
   160         FreeElementList(removeDevice->firstButton);
   151         FreeElementList(removeDevice->firstButton);
   161         FreeElementList(removeDevice->firstHat);
   152         FreeElementList(removeDevice->firstHat);
   878     recDevice *device = joystick->hwdata;
   869     recDevice *device = joystick->hwdata;
   879 
   870 
   880     /* Scale and average the two rumble strengths */
   871     /* Scale and average the two rumble strengths */
   881     Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
   872     Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
   882 
   873 
   883     if (!device) {
       
   884         return SDL_SetError("Rumble failed, device disconnected");
       
   885     }
       
   886 
       
   887     if (!device->ffservice) {
   874     if (!device->ffservice) {
   888         return SDL_Unsupported();
   875         return SDL_Unsupported();
   889     }
   876     }
   890 
   877 
   891     if (device->ff_initialized) {
   878     if (device->ff_initialized) {