Fixed crash on Mac OS X 10.10 and earlier
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Oct 2016 20:39:12 -0700
changeset 105546c07c69fb842
parent 10553 c1bb718f6c3f
child 10555 476a717c10cf
Fixed crash on Mac OS X 10.10 and earlier
src/video/cocoa/SDL_cocoakeyboard.m
     1.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Tue Oct 18 23:24:49 2016 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Wed Oct 19 20:39:12 2016 -0700
     1.3 @@ -195,6 +195,11 @@
     1.4  static void
     1.5  HIDCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value)
     1.6  {
     1.7 +    if (context != s_hidManager) {
     1.8 +        /* An old callback, ignore it (related to bug 2157 below) */
     1.9 +        return;
    1.10 +    }
    1.11 +
    1.12      IOHIDElementRef elem = IOHIDValueGetElement(value);
    1.13      if (IOHIDElementGetUsagePage(elem) != kHIDPage_KeyboardOrKeypad
    1.14          || IOHIDElementGetUsage(elem) != kHIDUsage_KeyboardCapsLock) {
    1.15 @@ -232,13 +237,14 @@
    1.16      if (!s_hidManager) {
    1.17          return;
    1.18      }
    1.19 +
    1.20 +#if 0 /* Releasing here causes a crash on Mac OS X 10.10 and earlier,
    1.21 +       * so just leak it for now. See bug 2157 for details.
    1.22 +       */
    1.23      IOHIDManagerUnscheduleFromRunLoop(s_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    1.24      IOHIDManagerRegisterInputValueCallback(s_hidManager, NULL, NULL);
    1.25      IOHIDManagerClose(s_hidManager, 0);
    1.26  
    1.27 -#if 0 /* Releasing here causes a crash on Mac OS X 10.10 and earlier,
    1.28 -       * so just leak it for now. See bug 2157 for details.
    1.29 -       */
    1.30      CFRelease(s_hidManager);
    1.31  #endif
    1.32      s_hidManager = NULL;
    1.33 @@ -267,7 +273,7 @@
    1.34          goto fail;
    1.35      }
    1.36      IOHIDManagerSetDeviceMatchingMultiple(s_hidManager, matches);
    1.37 -    IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, NULL);
    1.38 +    IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, s_hidManager);
    1.39      IOHIDManagerScheduleWithRunLoop(s_hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
    1.40      if (IOHIDManagerOpen(s_hidManager, kIOHIDOptionsTypeNone) == kIOReturnSuccess) {
    1.41          goto cleanup;