Guest User

Untitled

a guest
Aug 19th, 2019
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. HACK around FB6940492: Mac Catalyst: Crash when presenting view controllers
  3.  
  4. 'NSRangeException', reason: 'Cannot remove an observer <UINSSceneViewController 0x600003558790> for the key path "view.window.screen.contentLayoutRect" from <UINSSceneViewController 0x600003558790> because it is not registered as an observer.'
  5.  
  6. 0 CoreFoundation 0x00007fff3b20f183 __exceptionPreprocess + 250
  7. 1 libobjc.A.dylib 0x00007fff71719b64 objc_exception_throw + 48
  8. 2 Foundation 0x00007fff3d8ca2aa -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 578
  9. 3 Foundation 0x00007fff3d8ca01b -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 74
  10. 4 Foundation 0x00007fff3d8e2898 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 190
  11. 5 UIKitMacHelper 0x00007fff6c11e8ee -[UINSSceneViewController dealloc] + 298
  12. 6 Foundation 0x00007fff3d92f822 NSKVODeallocate + 172
  13. 7 AppKit 0x00007fff38518baa -[NSViewController release] + 119
  14. 8 AppKit 0x00007fff3869207e -[NSAutounbinder dealloc] + 44
  15. 9 libobjc.A.dylib 0x00007fff7172952a _ZN19AutoreleasePoolPage12releaseUntilEPP11objc_object + 134
  16. 10 libobjc.A.dylib 0x00007fff7170fc30 objc_autoreleasePoolPop + 175
  17. 11 FrontBoardServices 0x00007fff56e73255 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 228
  18. 12 FrontBoardServices 0x00007fff56e8a4bf __84-[FBSWorkspaceScenesClient _queue_invalidateScene:withTransitionContext:completion:]_block_invoke + 290
  19. 13 libdispatch.dylib 0x000000010dd9f84f _dispatch_client_callout + 8
  20. 14 libdispatch.dylib 0x000000010dda30a3 _dispatch_block_invoke_direct + 289
  21. 15 FrontBoardServices 0x00007fff56e59508 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
  22. */
  23. void PSPDFHackEatNSRangeExceptionsInSceneViewControllerDeallocation(void) {
  24. let clazz = NSClassFromString(@"UINSSceneViewController");
  25. if (!clazz) { return; }
  26. let selector = NSSelectorFromString(@"dealloc");
  27. __block IMP originalIMP = pspdf_swizzleSelectorWithBlock(clazz, selector, ^(__unsafe_unretained id _self) {
  28. @try {
  29. ((void (*)(id, SEL))originalIMP)(_self, selector);
  30. } @catch (...) {}
  31. });
  32. }
RAW Paste Data