Last active
October 19, 2019 12:00
-
-
Save steipete/e7bea1b1072e17eff7d584e651e81f2e to your computer and use it in GitHub Desktop.
Fixes Mac Catalyst: random crash inside [_UIBlurEffectCoreUIImpl _needsUpdateForTransitionFromEnvironment:toEnvironment:usage:] ()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use this code: (code incomplete, but you get the idea what needs to be done) | |
// TODO: Stop calling this once 10.15.1 is out! | |
#if TARGET_OS_UIKITFORMAC | |
static void PSPDFFixVisualEffectsEnvironment(void) { | |
static const char *PSPDFVisualEffectsWindowKey; | |
static const char *PSPDFVisualEffectsSuperviewKey; | |
let klass = NSClassFromString([NSString stringWithFormat:@"_%@sualEffe%@ironment", @"UIVi", @"ctEnv"]); | |
pspdf_swizzleSelectorWithBlock(klass, @selector(setWindow:), ^(NSObject *_self, UIWindow *window) { | |
[_self pspdf_setWeakAssociatedObject:window forKey:&PSPDFVisualEffectsWindowKey]; | |
}); | |
pspdf_swizzleSelectorWithBlock(klass, @selector(window), ^(NSObject *_self) { | |
return [_self pspdf_weakAssociatedObjectForKey:&PSPDFVisualEffectsWindowKey]; | |
}); | |
pspdf_swizzleSelectorWithBlock(klass, NSSelectorFromString([NSString stringWithFormat:@"set%@view:", @"Super"]), ^(NSObject *_self, UIView *superview) { | |
[_self pspdf_setWeakAssociatedObject:superview forKey:&PSPDFVisualEffectsSuperviewKey]; | |
}); | |
pspdf_swizzleSelectorWithBlock(klass, @selector(superview), ^(NSObject *_self) { | |
return [_self pspdf_weakAssociatedObjectForKey:&PSPDFVisualEffectsSuperviewKey]; | |
}); | |
} | |
#endif | |
If you see following crash: | |
lldb) bt | |
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20) | |
frame #0: 0x00007fff6cd0d708 libobjc.A.dylib`objc_retain + 24 | |
frame #1: 0x000000010fd7a8fe UIKitCore`-[_UIBlurEffectCoreUIImpl _needsUpdateForTransitionFromEnvironment:toEnvironment:usage:] + 275 | |
frame #2: 0x000000010f1667ed UIKitCore`-[UIBlurEffect _needsUpdateForTransitionFromEnvironment:toEnvironment:usage:] + 65 | |
frame #3: 0x000000010f17fe29 UIKitCore`-[UIVisualEffectView _updateEnvironmentAndFlagUpdatesIfNecessary:] + 312 | |
frame #4: 0x000000010f180142 UIKitCore`-[UIVisualEffectView _updateEffectForAppearsKeyChanges:] + 221 | |
frame #5: 0x00007fff3f9fa18f CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 | |
frame #6: 0x00007fff3fa8aa63 CoreFoundation`___CFXRegistrationPost1_block_invoke + 63 | |
frame #7: 0x00007fff3fa8a0f8 CoreFoundation`_CFXRegistrationPost1 + 372 | |
frame #8: 0x00007fff3fa027de CoreFoundation`___CFXNotificationPost_block_invoke + 97 | |
frame #9: 0x00007fff3f96aaf2 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1575 | |
frame #10: 0x00007fff3f969f82 CoreFoundation`_CFXNotificationPost + 1351 | |
frame #11: 0x00007fff41fde92b Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 59 | |
frame #12: 0x00000001111d036b UIKitMacHelper`-[UINSWindow _postWindowNotificationName:] + 89 | |
frame #13: 0x00007fff42031975 Foundation`__NSFireDelayedPerform + 415 | |
frame #14: 0x00007fff3f9b75b4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 | |
frame #15: 0x00007fff3f9b716e CoreFoundation`__CFRunLoopDoTimer + 859 | |
frame #16: 0x00007fff3f9b6b8e CoreFoundation`__CFRunLoopDoTimers + 317 | |
frame #17: 0x00007fff3f99793d CoreFoundation`__CFRunLoopRun + 2213 | |
frame #18: 0x00007fff3f996e13 CoreFoundation`CFRunLoopRunSpecific + 499 | |
frame #19: 0x00007fff3e63eb2d HIToolbox`RunCurrentEventLoopInMode + 292 | |
frame #20: 0x00007fff3e63e86d HIToolbox`ReceiveNextEventCommon + 600 | |
frame #21: 0x00007fff3e63e5f7 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 64 | |
frame #22: 0x00007fff3cef1d74 AppKit`_DPSNextEvent + 990 | |
frame #23: 0x00007fff3cef0ae4 AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352 | |
frame #24: 0x00007fff3ceeb284 AppKit`-[NSApplication run] + 658 | |
frame #25: 0x00007fff3cedd12d AppKit`NSApplicationMain + 777 | |
frame #26: 0x00007fff3d35e544 AppKit`_NSApplicationMainWithInfoDictionary + 16 | |
frame #27: 0x000000011119442c UIKitMacHelper`UINSApplicationMain + 322 | |
frame #28: 0x000000010ee95f94 UIKitCore`UIApplicationMain + 2206 | |
* frame #29: 0x000000010010ed39 Viewer`main at main.swift:12:1 | |
frame #30: 0x00007fff6e06b405 libdyld.dylib`start + 1 | |
frame #31: 0x00007fff6e06b405 libdyld.dylib`start + 1 | |
(lldb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment