Cell should never be in update animation (UICollectionView crash)

I've got Cell should never be in update animation crash in UICollectionView reported by crashlytics

This crash happens only for users on iOS 14. It wasn't noticeable when application used SDK iOS 13 (it affected less then 0.01 % of all users). But after supporting SDK iOS 14 crash frequency noticeably increased to almost 0.25 % of all users

Internally UICollectionView, as far as I understand (from some UIKit disassembly journey), loops through visible cells and checks that cell animation counter is equal zero (else it crashes with the following stack trace). It's not for sure but presumably crash happens while
performBatchUpdates(_:completion:)

I wasn't able to reproduce this bug and I can't spend more time on digging into UIKitCore disassembled code trying to understand when and why this animation counter changes
Code Block
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1915e9114 exceptionPreprocess
1 libobjc.A.dylib 0x1a4e0fcb4 objc_exception_throw
2 CoreFoundation 0x1914f8308 -[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3 Foundation 0x1927dc2c8 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKitCore 0x1935b8548 43-[UICollectionView _updateVisibleCellsNow:]_block_invoke_4.1070
5 UIKitCore 0x1935b8000 43-[UICollectionView _updateVisibleCellsNow:]_block_invoke.1053
6 libdispatch.dylib 0x191221298 _dispatch_call_block_and_release
7 libdispatch.dylib 0x191222280 _dispatch_client_callout
8 libdispatch.dylib 0x1911d123c _dispatch_main_queue_callback_4CF$VARIANT$mp
9 CoreFoundation 0x191568c30 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
10 CoreFoundation 0x1915630e8 CFRunLoopRun
11 CoreFoundation 0x191562200 CFRunLoopRunSpecific
12 GraphicsServices 0x1a765d598 GSEventRunModal
13 UIKitCore 0x193e28004 -[UIApplication _run]
14 UIKitCore 0x193e2d5d8 UIApplicationMain
15 Joom 0x100dd2d1c main + 49 (main.m:49)
16 libdyld.dylib 0x191241598 start


Did anyone faced with the same issue? Were you able to reproduce it?

Replies

We've been running into the same issue since iOS 13's release with a very similar crash trace. And we've also had a more than 3x spike in events since the release of iOS 14.

We're using performBatchUpdates alongside a FetchedResultsController, and also using performBatchUpdates to animate CollectionViewLayout changes, which doesn't seem out of the ordinary.

Code Block
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1b100d114 exceptionPreprocess
1 libobjc.A.dylib 0x1c4833cb4 objc_exception_throw
2 CoreFoundation 0x1b0f1c308 -[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3 Foundation 0x1b22002c8 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKitCore 0x1b2fdc548 43-[UICollectionView _updateVisibleCellsNow:]_block_invoke_4.1070
5 UIKitCore 0x1b2fdc000 43-[UICollectionView _updateVisibleCellsNow:]_block_invoke.1053
6 Foundation 0x1b22d2f8c NSFireDelayedPerform
7 CoreFoundation 0x1b0f8da30 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
8 CoreFoundation 0x1b0f8d634 CFRunLoopDoTimer
9 CoreFoundation 0x1b0f8cb14 CFRunLoopDoTimers
10 CoreFoundation 0x1b0f86eb0 __CFRunLoopRun
11 CoreFoundation 0x1b0f86200 CFRunLoopRunSpecific
12 GraphicsServices 0x1c7081598 GSEventRunModal
13 UIKitCore 0x1b384c004 -[UIApplication _run]
14 UIKitCore 0x1b38515d8 UIApplicationMain
15 App 0x104ffab74 main + 8 (main.m:8)
16 libdyld.dylib 0x1b0c65598 start


I've also got a similar crash popping up for iOS 14.* devices. The stack track is almost similar. I also try to replicate this on my device but not able to get this crash, but by looking at the firebase crashlytics reports, it is happening to some users. Please update once anyone gets a fix to avoid this crash.
I am having the same problem is there a fix yet??

In my case, I get the same error in [UIPageViewController setViewControllers:direction:animated:completion:]. I don't know how to fix this error yet.

Fatal Exception: NSInternalInconsistencyException (Unexpected subviews)
0  CoreFoundation                 0x1a0e229d8 __exceptionPreprocess
1  libobjc.A.dylib                0x1b51a5b54 objc_exception_throw
2  CoreFoundation                 0x1a0d3150c -[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3  Foundation                     0x1a202b878 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKitCore                      0x1a2f3bac4 -[_UIQueuingScrollView _setWrappedViewAtIndex:withView:]
5  UIKitCore                      0x1a2f3c04c -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:]
6  UIKitCore                      0x1a2f3d68c -[_UIQueuingScrollView _enqueueAnimatedScrollInDirection:withView:completion:]
7  UIKitCore                      0x1a2f3e1d4 -[_UIQueuingScrollView setView:direction:animated:completion:]
8  UIKitCore                      0x1a2f31e14 -[UIPageViewController _setViewControllers:withScrollInDirection:animated:completion:]
9  UIKitCore                      0x1a2f31ffc -[UIPageViewController setViewControllers:direction:animated:completion:]

Anyone found the solution ?