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

iOS 9 crash #94

Open
macsrok opened this issue Aug 20, 2015 · 8 comments
Open

iOS 9 crash #94

macsrok opened this issue Aug 20, 2015 · 8 comments

Comments

@macsrok
Copy link

macsrok commented Aug 20, 2015

I've been using LXReorderableCollectionViewFlowLayout in an app for over a year now. It works great in ios 7 and 8 but is crashing in iOS 9. I can reorder items as long as I don't need to scroll. As soon as the collection view scrolls it crashes.

I have narrowed it down to
- (void)invalidateLayoutIfNecessary

previousIndexPath is nil and causing a crash. If anyone has seen this or can offer some advice as to how to fix it, it would be greatly appreciated.

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x27b2244b 0x39426dff 0x27a3b3cd 0x27a455e5 0x16078e7 0x2c3718e7 0x2c371801 0x2bddb9cd 0x1607795 0x160a235 0x2c114457 0x2bd92177 0x2bc294b3 0x2c113c47 0x2bbeb1cf 0x2bbe8d87 0x2bc27431 0x2bc26b7b 0x2bbf85c1 0x25e40fdb 0x2bbf6f47 0x27ae5407 0x27ae4ff7 0x27ae335f 0x27a35d89 0x27a35b7d 0x30bc8af9 0x2bc5e99d 0x280feb 0x39b74873)
libc++abi.dylib: terminating with uncaught exception of type NSException

@nmcc24
Copy link

nmcc24 commented Aug 21, 2015

I'm experiencing a similar problem. Any time the collection view is scrolled, the following crash occurs:

*** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.4/UICollectionView.m:4211
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (16) must be equal to the number of items contained in that section before the update (16), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(0x21e5f44b 0x336aadff 0x21e5f321 0x22bec3d3 0x266abd5b 0x266ae973 0x266ae801 0x261189cd 0x4fb569 0x4fe00d 0x26451457 0x260cf177 0x25f664b3 0x26450c47 0x25f281cf 0x25f25d87 0x25f64431 0x25f63b7b 0x25f355c1 0x25f33f47 0x21e22407 0x21e21ff7 0x21e2035f 0x21d72d89 0x21d72b7d 0x2af45af9 0x25f9b99d 0xe7f25 0x33df8873)
libc++abi.dylib: terminating with uncaught exception of type NSException

As macsrok said, the exception occurs in invalidateLayoutIfNecessary:, upon the performBatchUpdates:, because previousIndexPath is nil

@TheCoordinator
Copy link

@macsrok @nmcc24 Is this still the case? I'm trying the example project o iOS 9 Beta 5 and seems to be fine.

@nmcc24
Copy link

nmcc24 commented Aug 24, 2015

@PeymanKh I did not try the example project until now, and it seems to be fine as well. However, in my app, in a very similar way, crashes in iOS9 beta 5, as I reported, whenever I try to scroll

@nmcc24
Copy link

nmcc24 commented Aug 24, 2015

and btw, My crash is different from the one reported by @macsrok because I check if previousIndexPath is nil before doing [strongSelf.collectionView deleteItemsAtIndexPaths:@[ previousIndexPath ]];

@nmcc24
Copy link

nmcc24 commented Aug 24, 2015

Further information about this problem:

I debugged deeper and the problem relies on - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer. On iOS8, it is called when the pan gesture (responsible for the scroll) is triggered, and on iOS9 it is not and jumps directly to the gesture's selector. Any tip?

@nmcc24
Copy link

nmcc24 commented Aug 26, 2015

Finally found out the issue, and perhaps that's what's happening to @macsrok as well.

What I was doing previously was creating a LXReorderableCollectionViewFlowLayout in viewDidLoad and then assigning it to the collectionView's collectionViewLayout. On iOS 9, this made the KVO trigger two times (one by the LXReorderableCollectionViewFlowLayout, and other by its superclass, collectionViewLayout). Therefore this led setupCollectionView to be ran twice, and thus the collectionView had two panGestureRecognizers. You can now understand why the crash occurred.

In order to solve this, I added the LXReorderableCollectionViewFlowLayout in the xib and now everything is running fine!

@cvburgess
Copy link

Also an issue for me - might want to incorporate a fix or add @nmcc24 's fix to the docs

@pomarec
Copy link

pomarec commented May 11, 2016

@nmcc24 thank you !

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

No branches or pull requests

5 participants