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

Fixes crash when accessing a cell within working range updates #216

Closed
wants to merge 1 commit into from

Conversation

rnystrom
Copy link
Contributor

Changes in this pull request

I was able to build a unit test that reproduces the issue. We can avoid the crash by simply returning nil when accessing a cell while working range events are being vended.

There is definitely something weird going on here though. When debugging cellForItemAtIndexPath: I found:

(lldb) po indexPath
<NSIndexPath: 0xc000000000000516> {length = 2, path = 5 - 0}
(lldb) po [[self collectionView] numberOfSections]
11

So in theory we should be fine, right? But when I continue I get

*** Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UICollectionViewData.m:611
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 5 when there are only 3 sections in the collection view'

There were 3 sections in the UICV before the update, but the data source and structure powering numberOfSections are updated.

-numberOfItemsBeforeSection: must be accessing some state that isn't set yet from the batch updates block. Unfortunately the details of that are private. Ideally -[UICollectionView cellForItemAtIndexPath:] would just return nil if it hasn't finished updating yet.

I'm a little skeptical about this fix, and this might require filing a radar with Apple.

Fixes #177

Pull request checklist

  • All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • I have reviewed the contributing guide

@jessesquires jessesquires modified the milestone: 2.0.0 Nov 17, 2016
Copy link
Contributor

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

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

Nice! 👍

Update CHANGELOG 😄

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@jessesquires jessesquires deleted the updates-crash branch November 18, 2016 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when calling performUpdates with workingRangeDelegate
3 participants