UICollectionView crash when inserting items quickly

Originator:adam
Number:rdar://12877037 Date Originated:13-Dec-2012 05:27 PM
Status:Duplicate/14332392 Resolved:
Product:iPhone SDK Product Version:6.0
Classification:Crash/Hang/Data Loss Reproducible:Always
 
WIth a UICollectionView using the stock UICollectionViewFlowLayout, calling insertItemsAtIndexPaths: too quickly can cause a crash.  Code that inserts a new item using insertItemsAtIndexPaths: into the UICollectionView every 0.05 seconds can cause a crash.

Steps to Reproduce:
1) Create a project. Set up a view controller with a UICollectionView and a UICollectionViewFlowLayout.
2) In viewDidAppear:, start inserting items into the collection view every 0.05 seconds. It is best to do this using dispatch_after.
1) Run the project on either the iOS 6.0 or 6.1 iPad simulator.
2) If the app doesn't crash within a few seconds, rerun the app.  About 60% of the time the app will crash with the error: 
*** Assertion failure in -[UICollectionViewData indexPathForItemAtGlobalIndex:], /SourceCache/UIKit_Sim/UIKit-2380.14/UICollectionViewData.m:442
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for index path for global index 1610612735 when there are only 1 items in the collection view'
*** First throw call stack:
(0x1c9b012 0x10cde7e 0x1c9ae78 0xb63f35 0x544ce0 0x52a0cb 0x523336 0x525b35 0x52308b 0x526aa5 0x526b69 0x2cb7 0x49fe53f 0x4a10014 0x4a007d5 0x1c41af5 0x1c40f44 0x1c40e1b 0x1bf57e3 0x1bf5668 0x1453c 0x242d 0x2355 0x1)
libc++abi.dylib: terminate called throwing an exception


Expected Results:
The app shouldn't crash when inserting items into the UICollectionView very quickly.

Actual Results:
The app crashes with the error in the Steps to Reproduce section.

Regression:
N/A

Comments

Still happens on iOS 7, but the exception has changed

Under iOS 7, the crash still happens however the error message has changed.

The error message is: 2013-06-12 14:50:59.962 BANANA[20656:c07] * Assertion failure in -[UICollectionViewCell addUpdateAnimation], /SourceCache/UIKitSim/UIKit-2776.18/UICollectionViewCell.m:146 2013-06-12 14:51:03.075 BANANA[20656:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'too many update animations on one view - limit is 15 in flight at a time (<UICollectionViewCell: 0x8a47f70; frame = (0 0; 50 50); animations = { opacity=; }; layer = >)' * First throw call stack: (0x2230028 0x13fa902 0x222fea8 0xdccb05 0x603ce1 0x5f9fa9 0x849a4 0x84c00 0x5f9a1c 0x5f5bb8 0x5fad04 0x5fade8 0x5f2a 0x56c8c32 0x56dd5a9 0x56cbb48 0x2294dce 0x21d5f59 0x21d559f 0x21d53eb 0x218d404 0x218d22b 0x24b6b 0x532d 0x5969725) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!