UICollectionView evenutally crashes when same NSIndexPath deleted more than once

Originator:rnystrom
Number:rdar://31786176 Date Originated:24-Apr-2017
Status:Open Resolved:
Product:UIKit Product Version:10.3.1
Classification:Crash Reproducible:Sometimes
 
Area:
UIKit

Summary:
If the same NSIndexPath is included in the array provided to -[UICollectionView deleteItemsAtIndexPaths:] more than once, eventually there will be an EXC_BAD_ACCESS in -[UICollectionViewData layoutAttributesForItemAtIndexPath:].

Say I have an NSMutableArray of data powering the data source of my UICollectionView, if I wanted to delete the head element twice, I might do something like:

[self.collectionView performBatchUpdates:^{
  NSArray *paths = @[
    [NSIndexPath indexPathForItem:0 inSection:0],
    [NSIndexPath indexPathForItem:0 inSection:0]
  ];
  [self.data removeObjectAtIndex:0];
  [self.data removeObjectAtIndex:0];
  [self.collectionView deleteItemsAtIndexPaths:paths];
} completion:nil];

If I repeat this action, or do other batch updates, eventually it will crash.

Steps to Reproduce:
1. Open sample app provided
2. Tap "Play" nav bar item a few times
3. Observe crash

Expected Results:
Delete the first two elements each time, don't crash.

Actual Results:
It will delete the first two elements, but after a few times tapping the "Play" item, it will crash.

Version:
10.3.1 (14E304)

Notes:


Configuration:
7 simulator, iPhone 7+

Attachments:
'UICollectionViewMultipleDeletesSameIndex.zip' and 'UICollectionViewMultipleDeletesSameIndex  4-24-17, 9-13 AM.crash' were successfully uploaded.

Comments


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!