Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix number of sections being out of bounds crash #108

Merged
merged 1 commit into from
Aug 3, 2022

Conversation

bryankeller
Copy link
Contributor

Details

layoutAttributesForItemAt: can be invoked with an out-of-bounds index path. Previous comments in code seem to indicate that this is not a new issue.

I believe the root of all of these issues is that the layout can be invalidated in between when the data source counts change (from a batch update), and when the layout actually receives an invalidate context specifying that data source counts have changed. This behavior sucks, and I don't see a clear way to work around this. This is something that I chatted about with a UICollectionView engineer back in 2019, and that person made it sound like they were using some private APIs in the layout to work around this 😩

Related Issue

N/A

Motivation and Context

Crash / assertion "fix" / workaround

How Has This Been Tested

Example project

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller added the bug Something isn't working label Aug 3, 2022
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MagazineLayout'
s.version = '1.6.9'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wish we could have stayed on this version longer 😞

Comment on lines +33 to +41
public override var debugDescription: String {
"Invalidate: everything - \(invalidateEverything), " +
"data source counts - \(invalidateDataSourceCounts), " +
"offset adjustment - \(contentOffsetAdjustment), " +
"size adjustment - \(contentSizeAdjustment), " +
"item index paths - \(String(describing: invalidatedItemIndexPaths)), " +
"supplementary index paths - \(String(describing: invalidatedSupplementaryIndexPaths)), " +
"decoration index paths - \(String(describing: invalidatedDecorationIndexPaths))"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was useful so just going to leave it in so I don't have to keep re-adding it locally

Comment on lines -382 to -383
// Returning `nil` rather than default/frameless layout attributes causes internal exceptions
// within `UICollectionView`, which is why we don't return `nil` here.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to repro this internal exception, and we return nil in other places, so seems ok to return nil

@bryankeller
Copy link
Contributor Author

Also, I used my separate app to slam this with randomized batch updates - no crashes or assertions 🥳

@bryankeller bryankeller merged commit d8c7a19 into master Aug 3, 2022
@bryankeller bryankeller deleted the bk/fix-number-of-sections-oob branch August 3, 2022 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants