Reputation: 213
I have been receiving this kind of crash from Crashlytics. It happens randomly anytime and its unreproducible. I have got a stack trace that points to an error of NaN in the frame property. but I can't find anything like this in my code also none of the thread contains code written by me, so its very hard to find the cause of this.
I am attaching the stack trace of the same.
`Fatal Exception: CALayerInvalidGeometry(CALayer position contains NaN: [nan 8])
0 CoreFoundation 0x191066fe0 __exceptionPreprocess
1 libobjc.A.dylib 0x18fac8538 objc_exception_throw
2 CoreFoundation 0x191066f28 -[NSException initWithCoder:]
3 QuartzCore 0x194375acc CA::Layer::set_position(CA::Vec2<double> const&, bool)
4 QuartzCore 0x194375c48 -[CALayer setPosition:]
5 QuartzCore 0x194376198 -[CALayer setFrame:]
6 UIKit 0x1977de83c __26-[_UILabelLayer setFrame:]_block_invoke
7 UIKit 0x1977de6cc -[_UILabelLayer _setFrameOrBounds:settingAction:]
8 UIKit 0x1977de7e8 -[_UILabelLayer setFrame:]
9 UIKit 0x19718a7a8 -[UIView(Geometry) setFrame:]
10 UIKit 0x19719a068 -[UILabel setFrame:]
11 UIKit 0x19719b3bc -[UIView(Geometry) sizeToFit]
12 UIKit 0x1972dc6ac -[UISegment _positionInfo]
13 UIKit 0x19753b7d4 -[UISegment layoutSubviews]
14 UIKit 0x19718e07c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
15 QuartzCore 0x19437e274 -[CALayer layoutSublayers]
16 QuartzCore 0x194372de8 CA::Layer::layout_if_needed(CA::Transaction*)
17 QuartzCore 0x194372ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
18 QuartzCore 0x1942ee34c CA::Context::commit_transaction(CA::Transaction*)
19 QuartzCore 0x1943153ac CA::Transaction::commit()
20 UIKit 0x1973ecbd8 _UIWindowUpdateVisibleContextOrder
21 UIKit 0x1973ec9e8 +[UIWindow _prepareWindowsPassingTestForAppResume:]
22 UIKit 0x1974285b0 -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]
23 UIKit 0x197427ef8 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]
24 UIKit 0x1974134a8 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke
25 UIKit 0x197413124 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]
26 UIKit 0x19774d7c8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:]
27 FrontBoardServices 0x192be222c __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.376
28 FrontBoardServices 0x192c0f884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
29 FrontBoardServices 0x192c0f6f0 -[FBSSerialQueue _performNext]
30 FrontBoardServices 0x192c0faa0 -[FBSSerialQueue _performNextFromRunLoopSource]
31 CoreFoundation 0x19101542c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
32 CoreFoundation 0x191014d9c __CFRunLoopDoSources0
33 CoreFoundation 0x1910129a8 __CFRunLoopRun
34 CoreFoundation 0x190f42da4 CFRunLoopRunSpecific
35 GraphicsServices 0x1929ac074 GSEventRunModal
36 UIKit 0x1971f6058 UIApplicationMain
37 XXXXXXXX 0x1000550ac main (main.m:14)
38 libdyld.dylib 0x18ff5159c start
`
The code for tweaking a UISegmentControl is as below, it's very old code. It was working fine until now.
for (id segment in [SegmentControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
//hear u add any of delegate function to increase the height and other label functionality in this
[label setTextAlignment:NSTextAlignmentCenter];
// [label setFont:[UIFont boldSystemFontOfSize:11]];
[(UILabel *)label setNumberOfLines:2];
//to adjust the label size manually with respect to text use below code
[(UILabel *)label setLineBreakMode:NSLineBreakByWordWrapping];
CGRect frame = [(UILabel *)label frame];
frame.size = [(UIView *)segment frame].size;
frame.size.width = (SegmentControl.frame.size.width / [[[[self currentField] definition] listOfValues] count]) - 4;
frame.origin.x = 2;
frame.origin.y = 0;
[(UILabel *)label setFrame:frame];
}
}
}
And also my app never crashes while executing this code specifically. And also listOfValues
is never empty. I am sure of that.
Upvotes: 0
Views: 334
Reputation: 66
Since you have the NaN issue, you have divided something by nil. As far as I see, you have divining operation only here, check the denominator for different cases and you will find the solution:
frame.size.width = (SegmentControl.frame.size.width / [[[[self currentField] definition] listOfValues] count]) - 4;
Upvotes: 1
Reputation: 4605
Run analyzer: Product -> Analyze. It will show you bad places in code. Looks like you have division by zero.
Upvotes: 1