提问人:eugene_prg 提问时间:4/9/2021 更新时间:12/17/2021 访问量:2945
应用程序关闭时出现奇怪的错误消息:“CALayer 位置包含 NaN:[nan nan]”
Weird error message on app close: “CALayer position contains NaN: [nan nan]”
问:
当我在物理设备上关闭我的应用程序时,我遇到了一条奇怪的错误消息。我在模拟器中做了同样的事情,但没有发生过这样的事情。
还尝试设置“事件引发时”断点,但 XCode 显示“未能在断点 4.2 的 0x1b3a7edd0处设置断点站点:”
关于是什么原因导致这种情况的任何想法?
2021-04-08 20:40:15.985908+0200 GoMom[21503:2008470] [SwiftUI] Invalid frame dimension (negative or non-finite).
2021-04-08 20:40:15.986074+0200 GoMom[21503:2008470] [SwiftUI] Invalid frame dimension (negative or non-finite).
2021-04-08 20:40:15.990231+0200 GoMom[21503:2008470] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x2824151a0; position = CGPoint (2 8); bounds = CGRect (0 0; 595 4); delegate = <UIView: 0x114d07cc0; frame = (2 8; 595 4); anchorPoint = (0, 0); autoresizesSubviews = NO; layer = <CALayer: 0x2824151a0>>; opaque = YES; allowsGroupOpacity = YES; anchorPoint = CGPoint (0 0); _swiftUI_displayListID = 1469; backgroundColor = <CGColor 0x2800f2220> [<CGColorSpace 0x2800ed200> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 1 1 0.232 )>'
*** First throw call stack:
(0x19e95d86c 0x1b3976c50 0x19e8564a4 0x1a1d85db4 0x1a1d85ce4 0x1a55f5378 0x1a58f1e38 0x1a58efb78 0x1a58eea8c 0x1a56585f0 0x1a53b09d0 0x1a5658158 0x1a5657f0c 0x1a565793c 0x1a5657f2c 0x1a565793c 0x1a5657f2c 0x1a565793c 0x1a56576d0 0x1a5657580 0x1a57167f4 0x1a52ca0ac 0x1a5868434 0x1a585e2c8 0x1a59e8f90 0x1a59e8fc4 0x1a185fec4 0x1a1d7a644 0x1a1d7ab18 0x1a1d8f30c 0x1a1cd4640 0x1a1cffb08 0x1a1d00e98 0x19e8d8358 0x19e8d25c4 0x19e8d2b74 0x19e8d221c 0x1b649c784 0x1a1312ee8 0x1a131875c 0x1003c93ac 0x19e5926b0)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x2824151a0; position = CGPoint (2 8); bounds = CGRect (0 0; 595 4); delegate = <UIView: 0x114d07cc0; frame = (2 8; 595 4); anchorPoint = (0, 0); autoresizesSubviews = NO; layer = <CALayer: 0x2824151a0>>; opaque = YES; allowsGroupOpacity = YES; anchorPoint = CGPoint (0 0); _swiftUI_displayListID = 1469; backgroundColor = <CGColor 0x2800f2220> [<CGColorSpace 0x2800ed200> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 1 1 0.232 )>'
terminating with uncaught exception of type NSException
warning: failed to set breakpoint site at 0x1b3976c14 for breakpoint 2.1: error sending the breakpoint request
warning: failed to set breakpoint site at 0x1b3976c14 for breakpoint 3.1: error sending the breakpoint request
warning: failed to set breakpoint site at 0x1b3976c14 for breakpoint 4.1: error sending the breakpoint request
warning: failed to set breakpoint site at 0x1b3a7edd0 for breakpoint 4.2: error sending the breakpoint request
答:
6赞
lorem ipsum
4/9/2021
#1
有两种可能性
首先,您使用了错误的框架方法.infinity
.frame(width: .infinity, height: .infinity, alignment: .center)
此方法需要有限值。
您只能在其中一个参数中使用它。max....
.frame(minWidth: 0, idealWidth: 100, maxWidth: .infinity, minHeight: 0, idealHeight: 100, maxHeight: .infinity, alignment: .center)
其次,您正在一个导致负值的帧中进行计算。
.frame(width: geo.size.width - 10, height: 100, alignment: .center)
使结果为负数。- 10
如果没有最小可重现示例,就不可能确切地告诉您问题出在哪里,但这应该可以让您接近。
1赞
Alessandro Pace
12/17/2021
#2
正如 @lorem Ipsum 在其答案的最后所说,如果没有更多信息,就很难解决此类错误。
我写这篇文章是为了帮助另一个有同样问题的人,调试 20 分钟后,我发现问题是我有 3 个无限数......所以 SwiftUI 无法与之配合使用。
对于任何有此错误的人,请耐心调试并按照断点进行操作,以真正查看 UI 中断的位置,然后找出错误是来自您为帧设置的数字还是帧本身的错误初始化。
下一个:Lua - 模块内的变量命名空间
评论