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

Crash (Assertion failure) in Pageboy.PatchedPageViewController when swiping fast #277

Closed
BasBuijsen opened this issue Oct 28, 2022 · 21 comments · Fixed by #278
Closed

Crash (Assertion failure) in Pageboy.PatchedPageViewController when swiping fast #277

BasBuijsen opened this issue Oct 28, 2022 · 21 comments · Fixed by #278

Comments

@BasBuijsen
Copy link
Contributor

BasBuijsen commented Oct 28, 2022

@msaps
We have 14 apps that are using pageboy as a dependency of Tabman and when we swipe about 10 pages fast after each other the app crashes with an Assertion failure. From the stacktrace we get an Assertion failure in Pageboy without any further specifications. We have a big userbase and it is currently causing a lot of crashes so a quick fix would be very helpful for us!

Our stacktrace:
`
2022-10-28 11:33:14.353745+0200 Groei[58716:22674120] *** Assertion failure in -[Pageboy.PatchedPageViewController queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:], UIPageViewController.m:2040

2022-10-28 11:33:14.357491+0200 Groei[58716:22674120] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UIView: 0x131686a70; frame = (0 0; 390 844); autoresize = W+H; backgroundColor = <UIDynamicCatalogColor: 0x282618320; name = Primary/Background>; layer = <CALayer: 0x28013e460>>'

*** First throw call stack:
(0x1affea248 0x1a93afa68 0x1aa96e81c 0x1b290014c 0x1b290a164 0x1b290ba9c 0x1b290926c 0x1b290a35c 0x1b28fde3c 0x1b28fe000 0x10592ba20 0x10592bef4 0x10592549c 0x105925194 0x1059246e8 0x105924ad0 0x100d482ac 0x100d48a40 0x100d4a97c 0x100d4ad30 0x10950a048 0x10950a8ac 0x1094b8a34 0x10950cdb4 0x10950cfac 0x10952d880 0x109532874 0x109533fd8 0x109532954 0x10950bcfc 0x10950c7b8 0x1094fca2c 0x10950bfd8 0x10950cdb4 0x10950cfac 0x10952d880 0x1094df5b0 0x1094df640 0x1094b900c 0x1094b8c78 0x10952a0e4 0x100ad84e8 0x100ad88e4 0x101b2584c 0x1019ffd74 0x1019dd364 0x1019ff498 0x1019436a0 0x100ad8114 0x100ad7dec 0x100ad7f48 0x100ec82cc 0x101b2584c 0x1019ffd74 0x1019dd364 0x101b9e71c 0x101bc7ad4 0x101b9e2f0 0x101b50a84 0x101b510f8 0x101b5133c 0x101b4fcc8 0x101b72cdc 0x101b6275c 0x101b6230c 0x101b6a014 0x101b69938 0x101b71440 0x101c3c140 0x101be9130 0x101c42e10 0x101bf108c 0x101bf1144 0x101bf1250 0x101b72980 0x101b637d8 0x101b6296c 0x101b60d30 0x101b6a5f4 0x101b69fd8 0x101b69bc4 0x101b46794 0x1019dd638 0x101b9e664 0x101b9e9b8 0x101b9e28c 0x101b50a84 0x101b51e78 0x101b84bf0 0x101b79b58 0x101b789b8 0x101b8d2a4 0x101e071a8 0x101e099ec 0x1b1174968 0x1069a0598 0x1069a204c 0x1069b2800 0x1069b2344 0x1b007aa08 0x1b005c368 0x1b00611e4 0x1e8e81368 0x1b2510d88 0x1b25109ec 0x100af1780 0x1ce385948)

libc++abi: terminating with uncaught exception of type NSException

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UIView: 0x131686a70; frame = (0 0; 390 844); autoresize = W+H; backgroundColor = <UIDynamicCatalogColor: 0x282618320; name = Primary/Background>; layer = <CALayer: 0x28013e460>>'
terminating with uncaught exception of type NSException
`

When anything more is needed you can let us know.

@BasBuijsen
Copy link
Contributor Author

BasBuijsen commented Nov 1, 2022

I did some more research and it may have to do with the animations.
stackoverflow post

@msaps
Copy link
Member

msaps commented Nov 1, 2022

@BasBuijsen yep I think this is unfortunately a well documented bug within UIPageViewController (which Pageboy embeds)...

Is this when interactively scrolling through dragging or triggering a page transition via a button interaction or similar?

@BasBuijsen
Copy link
Contributor Author

BasBuijsen commented Nov 1, 2022

@msaps This happens when a user swipes multiple times and fast after each other through pages. So not by clicking buttons

@BasBuijsen
Copy link
Contributor Author

@msaps Sorry to keep bothering you but can you look into a solution or a workaround because this is very high on our priority list?

@msaps
Copy link
Member

msaps commented Nov 2, 2022

@BasBuijsen I would love to solve it - however it isn't easily reproducible. Do you have a demo project/source code you can provide that showcases this issue?

A quick look on Google/StackOverflow shows this popping up a lot with use of UIPageViewController with numerous theories for how to resolve it. Being able to consistently reproduce it would help being able to potentially introduce a workaround.

@BasBuijsen
Copy link
Contributor Author

BasBuijsen commented Nov 2, 2022

@msaps Thank you for your help! I will try to make a demo project for you since our app is closed source. I will get back to you as soon as possible (probably tomorrow).

@BasBuijsen
Copy link
Contributor Author

@msaps i had a quick look if i could fix it myself and quite surprisingly i have fixed it. However i cant push a new branch because i don't have access. Can you either help me to push the branch or implement the code i changed?

Scherm­afbeelding 2022-11-03 om 10 54 07

As you can see i only added the isAnimating bool and check for it so it cannot start a new one when the previous is still happening. This fixed the crash for us.

@msaps
Copy link
Member

msaps commented Nov 3, 2022

@BasBuijsen amazing to hear that fixed it! I've raised a PR with the changes (credited to you of course): #278.

In future to contribute you just need to Fork the repo, commit your changes in your 'forked' repo and then create a PR into this one 🙂.

Will release this as 4.0.1 ASAP

@msaps msaps closed this as completed in #278 Nov 3, 2022
@BasBuijsen
Copy link
Contributor Author

@msaps Thank you for your help and fast responses! Do you have any idea when the new version will be available?

@msaps
Copy link
Member

msaps commented Nov 3, 2022

@BasBuijsen available now: 4.0.1

@BasBuijsen
Copy link
Contributor Author

@msaps Thank you very much! Is there also a new version for Tabman that uses this version? If not can that be created?

@msaps
Copy link
Member

msaps commented Nov 3, 2022

@BasBuijsen the latest version of Tabman (3.0.0) will support using Pageboy 4.0.1 - so just update the dependencies in whichever dependency manager you use 🙂

@msaps
Copy link
Member

msaps commented Nov 3, 2022

@BasBuijsen having looked further into this - I'm not sure how this would have solved the issue..

PatchedPageViewController.setViewControllers() is not called when swiping between pages - only when transitioning with animated transitions.

Can you reproduce the crash in the Pageboy example project / update it to potentially reproduce it? Would be really useful to reproduce the crash to try and fix it.

@BasBuijsen
Copy link
Contributor Author

BasBuijsen commented Nov 3, 2022

@msaps i added logs in the project to check when the crash appeared and it happened when this method was called. The stacktrace also refers to this class wich only contains one method Pageboy.PatchedPageViewController. After i added this it didn't happen again. This is the same solution thats provided in this stackoverflow post but thats in obj-c. According to that post it happens because this method is called while still animating the previous action. I will try to reproduce it in the example project so it can be tested but in our apps it is hard to consistently reproduce so i am not sure if i can.

@BasBuijsen
Copy link
Contributor Author

@msaps I didnt have time yet to test it with the demo project (i couldn't get the project working) but here are two videos of our apps with the bug and the change. In the first one i haven't changed anything and it is just version 4.0.1 of PageBoy. In the second video i made the same change as in my pr and as you can see the crash no longer appears and the animations are a lot nicer since they cannot start when a previous animation is still happening.

@msaps
Copy link
Member

msaps commented Nov 4, 2022

@BasBuijsen okay I see - please check out the latest changes on main and let me know if they resolve the issue - I merged #279 and cleaned the solution up a bit.

Also out of interest - are you calling PageboyViewController.reloadData() anywhere?

@BasBuijsen
Copy link
Contributor Author

@msaps I tested the newest version of main but it sometimes still causes the crash. This seems to cause the crash:

isAnimating = animated

And this fixes it for me:

isAnimating = true

This is because the updateViewControllers() is called with animated: false so it doesn't really do anything when setting isAnimated = animated

And yes we do call that function.

@msaps
Copy link
Member

msaps commented Nov 7, 2022

@BasBuijsen With 06a4150 the blocking logic is now applied universally regardless of animation - and will prevent parallel attempts to setViewControllers.

Where are you calling reloadData()? Is it during pagination / what is it being called to achieve?

@BasBuijsen
Copy link
Contributor Author

BasBuijsen commented Nov 8, 2022

@msaps Thank you!

Yes it is used during pagination. We have an infinite swiping feature where every page requests the next one from the api and when it gets the response the reloadData() is called.

@msaps
Copy link
Member

msaps commented Nov 8, 2022

@BasBuijsen now released 4.0.2 which has the latest changes in it 🙂

@BasBuijsen
Copy link
Contributor Author

@msaps Great! thanks for all your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants