Skip to content

UIKit semantics for when "visibleIndexPaths" is valid are not clear (.visibleNodes) #107

Description

@garrettmoon

From @nvh on October 20, 2015 8:11

Although it maybe doesn't make sense to call it directly in the performBatchUpdates block
- (void)collectionView:(ASCollectionView *)collectionView willDisplayNodeForItemAtIndexPath:(NSIndexPath *)indexPath; is called before the batch update completes as well, which can lead to this crash when calling 'visibleNodes' inside that delegate function:

2015-10-20 09:45:54.936 demo-app[99621:4521736] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000106c44f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001066bedeb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000106b28a94 -[__NSArrayM objectAtIndex:] + 212
    3   AsyncDisplayKit                     0x0000000106231662 -[ASDataController nodeAtIndexPath:] + 118
    4   AsyncDisplayKit                     0x000000010620bea0 -[ASCollectionView nodeForItemAtIndexPath:] + 28
    5   AsyncDisplayKit                     0x000000010620bb8f __32-[ASCollectionView visibleNodes]_block_invoke + 33
    6   CoreFoundation                      0x0000000106b86d7d __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 77
    7   CoreFoundation                      0x0000000106b86c4f -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 207
    8   AsyncDisplayKit                     0x000000010620bafe -[ASCollectionView visibleNodes] + 175
    9   demo-app                            0x0000000102de26cd _TFC10demo_app26ViewController18updateVisibleNodesfS0_FT_T_ + 157
    10  demo-app                            0x0000000102de3b92 _TFC10demo_app26ViewController14collectionViewfS0_FTGSQCSo16ASCollectionView_33willDisplayNodeForItemAtIndexPathGSQCSo11NSIndexPath__T_ + 50
    11  demo-app                            0x0000000102de3bf7 _TToFC10demo_app26ViewController14collectionViewfS0_FTGSQCSo16ASCollectionView_33willDisplayNodeForItemAtIndexPathGSQCSo11NSIndexPath__T_ + 71
    12  AsyncDisplayKit                     0x000000010620c417 -[ASCollectionView collectionView:willDisplayCell:forItemAtIndexPath:] + 169
    13  UIKit                               0x00000001040e92f1 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 2017
    14  UIKit                               0x00000001040ffef9 -[UICollectionView _viewAnimationsForCurrentUpdate] + 7236
    15  UIKit                               0x000000010410380b __62-[UICollectionView _updateWithItems:tentativelyForReordering:]_block_invoke1580 + 197
    16  UIKit                               0x0000000103984eec +[UIView(Animation) performWithoutAnimation:] + 65
    17  UIKit                               0x0000000104102c8e -[UICollectionView _updateWithItems:tentativelyForReordering:] + 2946
    18  UIKit                               0x00000001040fdd0c -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:] + 15456
    19  UIKit                               0x0000000104104c3e -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 415
    20  UIKit                               0x0000000104104a7c -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 74
    21  UIKit                               0x0000000104104a1f -[UICollectionView performBatchUpdates:completion:] + 53
    22  AsyncDisplayKit                     0x000000010620ce67 -[ASCollectionView rangeController:endUpdatesAnimated:completion:] + 369
    23  AsyncDisplayKit                     0x00000001062367ef __66-[ASRangeController dataController:endUpdatesAnimated:completion:]_block_invoke + 57
    24  AsyncDisplayKit                     0x000000010620f7c0 _Z37ASDisplayNodePerformBlockOnMainThreadU13block_pointerFvvE + 53
    25  AsyncDisplayKit                     0x000000010623676e -[ASRangeController dataController:endUpdatesAnimated:completion:] + 120
    26  AsyncDisplayKit                     0x000000010622f10a __50-[ASDataController endUpdatesAnimated:completion:]_block_invoke_3 + 57
    27  libdispatch.dylib                   0x000000010b8acef9 _dispatch_call_block_and_release + 12
    28  libdispatch.dylib                   0x000000010b8cd49b _dispatch_client_callout + 8
    29  libdispatch.dylib                   0x000000010b8b534b _dispatch_main_queue_callback_4CF + 1738
    30  CoreFoundation                      0x0000000106ba53e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    31  CoreFoundation                      0x0000000106b66939 __CFRunLoopRun + 2073
    32  CoreFoundation                      0x0000000106b65e98 CFRunLoopRunSpecific + 488
    33  GraphicsServices                    0x0000000108baead2 GSEventRunModal + 161
    34  UIKit                               0x00000001038df676 UIApplicationMain + 171
    35  demo-app                          0x00000001031d0e1d main + 109
    36  libdyld.dylib                       0x000000010b90192d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Copied from original issue: facebookarchive/AsyncDisplayKit#755

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions