PDFView Crash After Find Changing current selection and calling -scrollSelectionToVisible: on macOS Tahoe

Getting this crash after I do this in PDFKit a lot:

PDFSelection *nextSelect = [self.pdfView.document findString:currentSearchString fromSelection:currentSelction withOptions:NSCaseInsensitiveSearch]; if (nextSelect != nil) { self.pdfView.currentSelection = nextSelect; [self.pdfView scrollSelectionToVisible:nil]; }

Which often leads to:

0   CoreFoundation                      0x000000019ced4770 __exceptionPreprocess + 176
1   libobjc.A.dylib                     0x000000019c9b2418 objc_exception_throw + 88
2   CoreFoundation                      0x000000019cfffe10 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 724
3   CoreFoundation                      0x000000019cfa1ae4 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 52
4   PDFKit                              0x00000001cb56e0fc -[PDFView _axPostPageChangeNotification:] + 348
5   Foundation                          0x000000019e6a25e4 __NSFireDelayedPerform + 372
6   CoreFoundation                      0x000000019ce92290 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
7   CoreFoundation                      0x000000019ce91f50 __CFRunLoopDoTimer + 

Swizzle -_axPostPageChangeNotification: and don't call the original implementation avoids the crash...

you're welcome

Interestingly Preview.app seems to avoid the crash but they left the bug in for everyone else. cool.

My apologies this actually isn’t actually causing a crash…the exception is being thrown but apparently caught....

I hit my exception breakpoint in the debugger last night and had assumed a crash was imminent (because typically you're not supposed to recover from this type of error)

PDFView Crash After Find Changing current selection and calling -scrollSelectionToVisible: on macOS Tahoe
 
 
Q