UIPageViewController iOS9 crash

After installing iOS 9 on devices our app has been crashing when navigating to UIViewControllers containing UICollectionViews via a UIPageViewController. This is an iOS 9 specific crash. The following is the reason given for the crash:


Info: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectsAtIndexes:]: index 49 in index set beyond bounds for empty array'


It tends to be index 49 more often than not, but is not always this index.


Stack trace from a breakpoint exception of this crash

thread #1: tid = 0x1347e, 0x0000000196e53f48 libobjc.A.dylib

objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 16.1 frame #0: 0x0000000196e53f48 libobjc.A.dylib
objc_exception_throw
frame #1: 0x0000000182489a24 CoreFoundation
-[NSArray objectsAtIndexes:] + 1040 frame #2: 0x0000000187b16604 UIKit
-[UIAnimator removeAnimationsForTarget:ofKind:] + 160
frame #3: 0x0000000187b15f7c UIKit
-[UIScrollView(UIScrollViewInternal) _beginTrackingWithEvent:] + 176 frame #4: 0x0000000187b139e4 UIKit
-[UIScrollView _gestureRecognizer:shouldReceiveTouch:] + 164
frame #5: 0x0000000187b138c8 UIKit
-[UIGestureRecognizer _delegateShouldReceiveTouch:] + 100 frame #6: 0x000000018802e5cc UIKit
-[UIGestureRecognizer _shouldReceiveTouch:recognizerView:touchView:] + 268
frame #7: 0x0000000187f00cfc UIKit
__56-[UITouchesEvent _addGestureRecognizersForView:toTouch:]_block_invoke + 340 frame #8: 0x0000000187f008cc UIKit
_UIEventEnumerateGesturesForView + 384
frame #9: 0x0000000187f00b6c UIKit
-[UITouchesEvent _addGestureRecognizersForView:toTouch:] + 132 frame #10: 0x0000000187b06340 UIKit
-[UITouchesEvent _addTouch:forDelayedDelivery:] + 676
frame #11: 0x0000000187b06044 UIKit
_AddTouchToEvent + 204 frame #12: 0x0000000187d96358 UIKit
_UIApplicationHandleDigitizerEvent + 14508
frame #13: 0x0000000187ad5a74 UIKit
_UIApplicationHandleEventQueue + 4160 frame #14: 0x00000001825385a4 CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
frame #15: 0x0000000182538038 CoreFoundation
__CFRunLoopDoSources0 + 540 frame #16: 0x0000000182535d38 CoreFoundation
__CFRunLoopRun + 724
frame #17: 0x0000000182464dc0 CoreFoundation
CFRunLoopRunSpecific + 384 frame #18: 0x000000018d3e0088 GraphicsServices
GSEventRunModal + 180
frame #19: 0x0000000187b3ef60 UIKit`UIApplicationMain + 204
frame #20: 0x00000001000782c4 M-GO
main(argc=1, argv=0x000000016fdb7a88) + 124 at main.m:14 frame #21: 0x00000001976728b8 libdyld.dylib
start + 4


And here is the backtrace without the breakpoint exception

thread #1: tid = 0x37da, 0x000000019b22b1e0 libsystem_kernel.dylib

__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x000000019b22b1e0 libsystem_kernel.dylib
pthread_kill + 8
frame #1: 0x000000019b2f4f0c libsystem_pthread.dylib
pthread_kill + 112 frame #2: 0x000000019b19eb78 libsystem_c.dylib
abort + 140
frame #3: 0x0000000199f6d3f4 libc++abi.dylib
abort_message + 132 frame #4: 0x0000000199f86f60 libc++abi.dylib
std::terminate(void (*)()) + 44
frame #5: 0x0000000199f86b10 libc++abi.dylib
__cxa_rethrow + 144 frame #6: 0x000000019a8f0120 libobjc.A.dylib
objc_exception_rethrow + 44
frame #7: 0x0000000185e28e68 CoreFoundation
CFRunLoopRunSpecific + 552 frame #8: 0x0000000190dbc088 GraphicsServices
GSEventRunModal + 180
frame #9: 0x000000018b502f60 UIKit`UIApplicationMain + 204
  • frame #10: 0x00000001000402c4 M-GO
    main(argc=1, argv=0x000000016fdefa88) + 124 at main.m:14 frame #11: 0x000000019b10e8b8 libdyld.dylib
    start + 4

This is probably the same bug, still present in iOS 13, which has been reported to Apple as FB7538414.

UIPageViewController iOS9 crash
 
 
Q