Skip to content

Commit

Permalink
Fixed crash on Mac OS X 10.10 and earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 20, 2016
1 parent 012217f commit 6d67c98
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -195,6 +195,11 @@ - (NSArray *)validAttributesForMarkedText
static void
HIDCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value)
{
if (context != s_hidManager) {
/* An old callback, ignore it (related to bug 2157 below) */
return;
}

IOHIDElementRef elem = IOHIDValueGetElement(value);
if (IOHIDElementGetUsagePage(elem) != kHIDPage_KeyboardOrKeypad
|| IOHIDElementGetUsage(elem) != kHIDUsage_KeyboardCapsLock) {
Expand Down Expand Up @@ -232,13 +237,14 @@ - (NSArray *)validAttributesForMarkedText
if (!s_hidManager) {
return;
}
IOHIDManagerUnscheduleFromRunLoop(s_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterInputValueCallback(s_hidManager, NULL, NULL);
IOHIDManagerClose(s_hidManager, 0);

#if 0 /* Releasing here causes a crash on Mac OS X 10.10 and earlier,
* so just leak it for now. See bug 2157 for details.
*/
IOHIDManagerUnscheduleFromRunLoop(s_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterInputValueCallback(s_hidManager, NULL, NULL);
IOHIDManagerClose(s_hidManager, 0);

CFRelease(s_hidManager);
#endif
s_hidManager = NULL;
Expand Down Expand Up @@ -267,7 +273,7 @@ - (NSArray *)validAttributesForMarkedText
goto fail;
}
IOHIDManagerSetDeviceMatchingMultiple(s_hidManager, matches);
IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, NULL);
IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, s_hidManager);
IOHIDManagerScheduleWithRunLoop(s_hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
if (IOHIDManagerOpen(s_hidManager, kIOHIDOptionsTypeNone) == kIOReturnSuccess) {
goto cleanup;
Expand Down

0 comments on commit 6d67c98

Please sign in to comment.