Alua-Kinzhebayeva / iOS-PDF-Reader

PDF Reader for iOS written in Swift
MIT License
533 stars 150 forks source link

NSInvalidArgumentException: attempt to scroll to invalid index path: <NSIndexPath: 0x174232ce0> {length = 2, path = 0 - 4} #60

Open aaronjrenfroe opened 7 years ago

aaronjrenfroe commented 7 years ago

So, I've got a single crash report from a live app and the reason given was:

NSInvalidArgumentException: attempt to scroll to invalid index path: <NSIndexPath: 0x174232ce0> {length = 2, path = 0 - 4}

I'm not too worried about it, i'm just trying to figure out how it happened/how it can be prevented. The crash appeared to have taken place in PDFThumbnailCollectionViewController :

if !collectionView.indexPathsForVisibleItems.contains(curentPageIndexPath) { collectionView.scrollToItem(at: curentPageIndexPath, at: .centeredHorizontally, animated: true) } but you are checking if the collectionview has that indexPath and if true, you are going to it, but the crash appears to say that you tried to go to an index path the the cv did not have.

Partial stack trace

0 CoreFoundation
__exceptionPreprocess + 124
1 libobjc.A.dylib
objc_exception_throw + 52
2 CoreFoundation
+[NSException raise:format:] + 112
3 UIKit
-[UICollectionView _contentOffsetForScrollingToItemAtIndexPath:atScrollPosition:] + 220
4 UIKit
-[UICollectionView scrollToItemAtIndexPath:atScrollPosition:animated:] + 68
5 PDFReaderPDFThumbnailCollectionViewController.swift:30
currentPageIndex.didset
6 PDFReaderPDFViewController.swift
scrollViewDidScroll
7 PDFReaderPDFViewController.swift
scrollViewDidScroll
ranunez commented 6 years ago

Ahh, thanks for the stack trace, we can see whats going on

barzhomi commented 6 years ago

That's issue appears every time when you trying to scroll the list of document pages after the last page. If the last page scrolled for more than half a screen the app crash because the list of thumbnails trying to set current thumbnail index out of the bound.

Y2JChamp commented 5 years ago

Was it solved? I ran into the same issue when rotating the device multiple times

22CLG commented 5 years ago

Was this solved? I have same issue

aaronjrenfroe commented 5 years ago

It’s been a couple years but I believe I just edited the code in the pod to add a check if it was out of range.

-Aaron

On Apr 14, 2019, at 04:23, 22CLG notifications@github.com<mailto:notifications@github.com> wrote:

Was this solved? I have same issue

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Alua-Kinzhebayeva/iOS-PDF-Reader/issues/60#issuecomment-482929940, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AVFcVTI9aVZq9O0KYJaszKiwJMRbX4nAks5vguVcgaJpZM4O25GL.