Closed SNagappan closed 4 years ago
Hi @SNagappan - thanks for finding this bug and making a fix. Before I approve, I just want to understand a bit more about how this crash is possible. Do you have a repro case? I'm trying to figure out why shouldInvalidateLayout
is getting called with an empty index path in the first place.
Ah, I see you emailed me some additional context. Thanks for that! So weird that this is happening. Looks like it might be related to voiceover / UIAccessibility, which would explain why it's so rare in your project.
Crashed: com.apple.main-thread
0 libswiftUIKit.dylib 0x1c285a0c8 IndexPath.section.getter + 168
1 MagazineLayout 0x1037be1e8 itemModelHeightModeDuringPreferredAttributesCheck #1 (at:sectionModels:) in ModelState.itemModelHeightModeDuringPreferredAttributesCheck(at:) + 118 (ModelState.swift:118)
2 MagazineLayout 0x1037afe38 MagazineLayout.shouldInvalidateLayout(forPreferredLayoutAttributes:withOriginalAttributes:) + 132 (ModelState.swift:132)
3 MagazineLayout 0x1037b020c @objc MagazineLayout.shouldInvalidateLayout(forPreferredLayoutAttributes:withOriginalAttributes:) + 4379738636 (<compiler-generated>:4379738636)
4 UIKitCore 0x1b1c352a8 -[UICollectionView _checkForPreferredAttributesInView:originalAttributes:] + 656
5 UIKitCore 0x1b1c36838 -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:] + 880
6 UIKitCore 0x1b1c5c0f4 -[UICollectionView preferredFocusedView] + 2404
7 UIKit 0x1f578b9fc -[UICollectionViewAccessibility preferredFocusedView] + 56
8 UIKitCore 0x1b1f3bd28 __UIFocusEnvironmentPreferredFocusedView + 64
9 UIKitCore 0x1b29929e0 -[UIView preferredFocusEnvironments] + 48
10 UIKit 0x1f5815858 -[UIViewAccessibility preferredFocusEnvironments] + 68
11 UIKitCore 0x1b1f3bdb0 _UIFocusEnvironmentEffectivePreferredFocusEnvironments + 72
12 UIKitCore 0x1b1f4cce4 -[_UIFocusEnvironmentPreferenceEnumerationContext _resolvePreferredFocusEnvironments] + 224
13 UIKitCore 0x1b1f4cbc4 -[_UIFocusEnvironmentPreferenceEnumerationContext prefersNothingFocused] + 40
14 UIKitCore 0x1b1f4d8ec _enumeratePreferredFocusEnvironments + 184
15 UIKitCore 0x1b1f4d74c -[_UIFocusEnvironmentPreferenceEnumerator enumeratePreferencesForEnvironment:usingBlock:] + 200
16 UIKitCore 0x1b1f4dfe8 -[_UIDeepestPreferredEnvironmentSearch deepestPreferredFocusableItemForEnvironment:withRequest:] + 592
17 UIKitCore 0x1b1f92484 -[UIFocusUpdateContext _updateDestinationItemIfNeeded] + 232
18 UIKitCore 0x1b1f9227c -[UIFocusUpdateContext _destinationItemInfo] + 28
19 UIKitCore 0x1b1f92158 -[UIFocusUpdateContext nextFocusedItem] + 24
20 UIKitCore 0x1b1f81bf8 -[UIFocusSystem updateFocusIfNeeded] + 192
21 UIKitCore 0x1b1c3d0cc __43-[UICollectionView _updateVisibleCellsNow:]_block_invoke.1183 + 184
22 UIKitCore 0x1b29a4d0c +[UIView(Animation) performWithoutAnimation:] + 96
23 UIKitCore 0x1b1c3b6f0 -[UICollectionView _updateVisibleCellsNow:] + 9220
24 UIKitCore 0x1b1c3ed38 -[UICollectionView layoutSubviews] + 320
25 UIKitCore 0x1b29b1954 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2464
26 QuartzCore 0x1b2eb19e8 -[CALayer layoutSublayers] + 288
27 QuartzCore 0x1b2eb7eb4 CA::Layer::layout_if_needed(CA::Transaction*) + 520
28 QuartzCore 0x1b2ec31d0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 140
29 QuartzCore 0x1b2e0f500 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 416
30 QuartzCore 0x1b2e39698 CA::Transaction::commit() + 728
31 QuartzCore 0x1b2e3a948 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
32 CoreFoundation 0x1afbebecc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
33 CoreFoundation 0x1afbe65b0 __CFRunLoopDoObservers + 604
34 CoreFoundation 0x1afbe6af8 __CFRunLoopRun + 960
35 CoreFoundation 0x1afbe6200 CFRunLoopRunSpecific + 572
36 GraphicsServices 0x1c5ce1598 GSEventRunModal + 160
37 UIKitCore 0x1b24ac004 -[UIApplication _run] + 1052
38 UIKitCore 0x1b24b15d8 UIApplicationMain + 164
Details
shouldInvalidateLayout crashes if IndexPath is empty
Related Issue
https://github.com/airbnb/MagazineLayout/pull/77
Types of changes
Checklist