CG_NUMERICS_SHOW_BACKTRACE 究竟做了什么

use*_*829 6 calayer uilabel ios cgrect swift

在我的项目中,我遇到了很多崩溃

CALayerInvalidGeometry; CALayer 边界包含 NaN:

但我无法重现崩溃,只能在 Fabric 中找到它,因此无法在此处共享代码,因为我无法上传整个项目。

我从 Fabric 收到以下消息。

当心!CALayerInvalidGeometry; CALayer 边界包含 NaN:[...] 详细信息:此崩溃可能是由于在将变换应用于视图或图层时被零除所致。在 Xcode 中设置 'CG_NUMERICS_SHOW_BACKTRACE' 环境变量可以帮助查明根本原因。查看以下参考资料了解更多详情。

将 CG_NUMERICS_SHOW_BACKTRACE 设置为 YES 到底有什么作用?

我可以在我的项目中搜索哪些可能的原因?仅搜索项目中的所有 CGRect 就足够了吗?

我怎么能在测试应用程序中创建这个崩溃?

我尝试了以下方法来重现它

var bounds: CGRect = CGRect(x: 0, y: 0, width: 0, height: 0)
let int = apiToken != nil ? 0 : 5
bounds.size = CGSize(width: 5/int, height: 5)
self.bounds = bounds
Run Code Online (Sandbox Code Playgroud)

但刚刚除以零错误。

这是堆栈跟踪。

Fatal Exception: CALayerInvalidGeometry
0  CoreFoundation                 0x1856b7d38 __exceptionPreprocess
1  libobjc.A.dylib                0x184bcc528 objc_exception_throw
2  CoreFoundation                 0x1856b7c80 -[NSException initWithCoder:]
3  QuartzCore                     0x18969d8ac CA::Layer::set_bounds(CA::Rect const&, bool)
4  QuartzCore                     0x18968f730 -[CALayer setBounds:]
5  UIKit                          0x18f1ee7ec __27-[_UILabelLayer setBounds:]_block_invoke
6  UIKit                          0x18f1ee588 -[_UILabelLayer _setFrameOrBounds:settingAction:]
7  UIKit                          0x18f1ee798 -[_UILabelLayer setBounds:]
8  QuartzCore                     0x18968fe28 -[CALayer setFrame:]
9  UIKit                          0x18f1ee6fc __26-[_UILabelLayer setFrame:]_block_invoke
10 UIKit                          0x18f1ee588 -[_UILabelLayer _setFrameOrBounds:settingAction:]
11 UIKit                          0x18f1ee6a8 -[_UILabelLayer setFrame:]
12 UIKit                          0x18eac0818 -[UIView(Geometry) setFrame:]
13 UIKit                          0x18eacfd54 -[UILabel setFrame:]
14 UIKit                          0x18f64cacc -[_UITAMICAdaptorView layoutSubviews]
15 UIKit                          0x18eac4000 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
16 QuartzCore                     0x1896950b4 -[CALayer layoutSublayers]
17 QuartzCore                     0x189699194 CA::Layer::layout_if_needed(CA::Transaction*)
18 QuartzCore                     0x189607f24 CA::Context::commit_transaction(CA::Transaction*)
19 QuartzCore                     0x18962e340 CA::Transaction::commit()
20 QuartzCore                     0x18962f180 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
21 CoreFoundation                 0x18565f8b8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
22 CoreFoundation                 0x18565d270 __CFRunLoopDoObservers
23 CoreFoundation                 0x18565d82c __CFRunLoopRun
24 CoreFoundation                 0x18557e2d8 CFRunLoopRunSpecific
25 GraphicsServices               0x18740ff84 GSEventRunModal
26 UIKit                          0x18eb2a880 UIApplicationMain
27 ProjectName                    0x1001efe98 main (AppDelegate.swift:21)
28 libdyld.dylib                  0x1850a256c start
Run Code Online (Sandbox Code Playgroud)