Fix _flushViewController crash by using viewController index map#301
Merged
Merged
Conversation
When UIPageViewController asks for the view controller before/after a given view controller, the current implementation uses `currentIndex` to determine which page to return. However, `currentIndex` can become stale after a cancelled or interrupted transition, causing the data source to return an incorrect view controller. This leads to an internal state inconsistency in UIPageViewController, which eventually triggers a `_flushViewController` crash. This fix resolves the issue by looking up the actual index of the passed `viewController` from `viewControllerIndexMap` first, falling back to `currentIndex` only when the view controller is not found in the map. This ensures the correct adjacent page is always returned, regardless of whether `currentIndex` has been updated yet. Refs: uias#286 Refs: uias/Tabman#556
Member
|
Thanks @sanghun0724! |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a crash in
UIPageViewController's internal_flushViewControllermethod caused by stalecurrentIndexvalues in theUIPageViewControllerDataSourcemethods.@msaps
Root cause:
pageViewController(_:viewControllerBefore:)andpageViewController(_:viewControllerAfter:)usecurrentIndexto determine which adjacent page to return. After a cancelled or interrupted page transition,currentIndexcan become stale (not yet updated to reflect the actual displayed page). This causes the data source to return an incorrect view controller, leading to an internal state inconsistency inUIPageViewControllerthat triggers the_flushViewControllercrash.Fix: Use
viewControllerIndexMap.index(for: viewController)to look up the actual index of theviewControllerparameter passed byUIPageViewController, falling back tocurrentIndexonly when the view controller is not found in the map. This ensures the correct adjacent page is always returned regardless ofcurrentIndexstate.Safety: This change is backward-compatible.
viewControllerIndexMapalready tracks all managed view controllers and their indices. The fallback tocurrentIndexpreserves existing behavior for any edge case where the view controller is not in the map.Related Issues
Test Plan
swift buildpasses successfully