系统控件和系统堆栈的crash初看,总以为不好解决,本文通过一步步推导来分析定位,最终找到crash是应用堆栈触发的
一、问题描述
最新线上新版本遇到了一个大规模的crash,也不太好复现,crash堆栈大概如下
0 CoreFoundation 0x00000001819f6d8c ___exceptionPreprocess + 228
1 libobjc.A.dylib 0x0000000180bb05ec objc_exception_throw + 44
2 CoreFoundation 0x00000001819f6c6c -[NSException initWithCoder:]
3 UIKit 0x000000018bfe3134 -[UIPageViewController _validatedViewControllersForTransitionWithViewControllers:animated:] + 588
4 UIKit 0x000000018bfe3cbc -[UIPageViewController _setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:] + 568
5 UIKit 0x000000018bfe6da0 -[UIPageViewController _handlePanGesture:] + 292
6 UIKit 0x000000018b7e26e8 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
7 UIKit 0x000000018bd4f3b4 __UIGestureRecognizerSendTargetActions + 124
8 UIKit 0x000000018b944e38 __UIGestureRecognizerSendActions + 320
9 UIKit 0x000000018b7e1740 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 764
10 UIKit 0x000000018bd40bd4 __UIGestureEnvironmentUpdate + 1096
11 UIKit 0x000000018b7db4d8 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
12 UIKit 0x000000018b7db010 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 276
13 UIKit 0x000000018b7da874 -[UIWindow sendEvent:] + 3132
23 UIKit 0x000000018b8d9758 UIApplicationMain + 228
24 mttlite 0x0000000102a843f4 main (main.mm:35)
25 libdyld.dylib 0x000000018134dfc0 _start + 4
The number of view controllers provided (0) doesn't match the number required (2) for the requested transition
二、问题分析
2.1开始
咋一看,这个和UITableView等类似的the number of section after updated(xxx) does not match before(xxx) … 类似,以为是不是命中了系统的什么bug,但是看了一圈代码也没找到有特殊的逻辑;
再观察所有crash记录,发现出现问题时必有如下handlePanGesture的操作,难道这里有什么系统的bug吗?
而且由于这个问题很难复现到,所以一时就无从下手了。
5 UIKit 0x000000018bfe6da0 -[UIPageViewController _handlePanGesture:] + 292
2.2分析问题
既然复现也不好复现,那就看从crash里找信息吧
3 UIKit 0x000000018bfe3134 -[UIPageViewController _validatedViewControllersForTransitionWithViewControllers:animated:] + 588