Fscalendar: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [155 nan]'

Created on 25 May 2017  路  15Comments  路  Source: WenchaoD/FSCalendar

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [155 nan]'

I have used FSCalendar for displaying dates, When I vertically scroll up, it works perfectly fine but when I scroll down, it just crashes and displays this error?

How should I resolve this or how should I stop my calendar to scroll vertically?

Most helpful comment

I too was getting this exception, but I realized that the calendar delegate and dataSource were not configured. The exception disappeared after I added them.

All 15 comments

Same thing happened to me. I tried to follow FSCalendarScopeExampleViewController and put it my own view controller. Then it will crash and throw same error.

same here. any help?

Guys, could you please provide at least the stack trace or some more precise info if you expecting for some help here.

let scopeGesture = UIPanGestureRecognizer(target: self.calendar, action: #selector(self.calendar.handleScopeGesture(_:)))
self.calendar.addGestureRecognizer(scopeGesture)

here's what I got every time I try to use handleScopeGesture :

error in __connection_block_invoke_2: Connection interrupted
2017-06-29 15:41:43.103844 *[3850:163138] * Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [207 nan]'
*
* First throw call stack:
(0x190fa01c0 0x18f9d855c 0x190fa0108 0x1942a5db8 0x1942a5f2c 0x1942a64c4 0x196de2c40 0x196e06efc 0x196e98924 0x1001124d0 0x100154390 0x10014cc88 0x10014b978 0x1000cd664 0x1973b783c 0x1973baf44 0x196f7c614 0x196e1ab54 0x1973aaf88 0x1973aaae8 0x1973a9da4 0x196e18d70 0x196de9858 0x1975d6cb8 0x1975d0720 0x190f4e278 0x190f4dbc0 0x190f4b7c0 0x190e7a048 0x1928fd198 0x196e54628 0x196e4f360 0x1001899dc 0x18fe5c5b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

i meet the same problem. and the stacks followed

* Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [206 nan]'
*
First throw call stack:
(
0 CoreFoundation 0x000000010543cb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000104ea1141 objc_exception_throw + 48
2 CoreFoundation 0x00000001054a5625 +[NSException raise:format:] + 197
3 QuartzCore 0x000000010afcc0be _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4 QuartzCore 0x000000010afcc231 -[CALayer setPosition:] + 43
5 QuartzCore 0x000000010afcc851 -[CALayer setFrame:] + 610
6 UIKit 0x0000000105fecc99 -[UIView(Geometry) setFrame:] + 845
7 UIKit 0x000000010601b096 -[UIScrollView setFrame:] + 149
8 UIKit 0x000000010687887a -[UICollectionView setFrame:] + 615
9 FSCalendar 0x00000001049081f8 -[UIView(FSCalendarExtensions) setFs_top:] + 232
10 FSCalendar 0x000000010491bd13 -[FSCalendarTransitionCoordinator performPathAnimationWithProgress:] + 1331
11 FSCalendar 0x00000001049134c4 -[FSCalendarTransitionCoordinator scopeTransitionDidUpdate:] + 1828
12 FSCalendar 0x0000000104911e37 -[FSCalendarTransitionCoordinator handleScopeGesture:] + 151
13 FSCalendar 0x00000001048eabeb -[FSCalendar handleScopeGesture:] + 155
14 UIKit 0x000000010647dc09 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
15 UIKit 0x0000000106485a07 _UIGestureRecognizerSendTargetActions + 109
16 UIKit 0x00000001064833bb _UIGestureRecognizerSendActions + 225
17 UIKit 0x000000010648267e -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981
18 UIKit 0x000000010646ee02 _UIGestureEnvironmentUpdate + 1219
19 UIKit 0x000000010646e8f3 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
20 UIKit 0x000000010646daba -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
21 UIKit 0x0000000105fb9b9a -[UIWindow sendEvent:] + 4092
22 UIKit 0x0000000105f667b0 -[UIApplication sendEvent:] + 352
23 UIKit 0x0000000106749adc __dispatchPreprocessedEventFromEventQueue + 2926
24 UIKit 0x0000000106741a3a __handleEventQueue + 1122
25 CoreFoundation 0x00000001053e2c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
26 CoreFoundation 0x00000001053c80cf __CFRunLoopDoSources0 + 527
27 CoreFoundation 0x00000001053c75ff __CFRunLoopRun + 911
28 CoreFoundation 0x00000001053c7016 CFRunLoopRunSpecific + 406
29 GraphicsServices 0x000000010a7ffa24 GSEventRunModal + 62
30 UIKit 0x0000000105f490d4 UIApplicationMain + 159
31 venus 0x00000001047a9b0f main + 111
32 libdyld.dylib 0x000000010879965d start + 1
33 ??? 0x0000000000000001 0x0 + 1

Thank you @honghom212, this is much better.

I too was getting this exception, but I realized that the calendar delegate and dataSource were not configured. The exception disappeared after I added them.

@ravi-enc thx, u are right. the problem is solved.

@WenchaoD looks like a good reason to add some assert to avoid such issues in the future.

I am running into this problem too. I read through this and have declared my data source and delegate. See below.

Stack Trace:
* Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [162.5 nan]'
*
First throw call stack:
(0x183bf6364 0x182e3c528 0x183bf62ac 0x187c42690 0x187c3463c 0x187c34bf8 0x18d0d16b0 0x18d0f5b78 0x18d176324 0x1041f0bbc 0x104202474 0x1041fad8c 0x1041f9a78 0x1041d4200 0x18d774cd0 0x18d7792c4 0x18d251aa8 0x18d108c38 0x18d762b34 0x18d7626a4 0x18d761800 0x18d106f44 0x18d0d7f64 0x18da2d31c 0x18da2f8a8 0x18da287c0 0x183b9e97c 0x183b9e8fc 0x183b9e184 0x183b9bd5c 0x183abbe58 0x185968f84 0x18d13b67c 0x1028ef64c 0x1835d856c)
libc++abi.dylib: terminating with uncaught exception of type NSException

ViewDidLoad function where I declared the data source/delegate:
`override func viewDidLoad() {

    super.viewDidLoad()
    iduser = 1
    self.FSCalendar.select(Date())
    self.view.addGestureRecognizer(self.scopeGesture)
    self.TableView.panGestureRecognizer.require(toFail: self.scopeGesture)
    self.FSCalendar.scope = .week
    FSCalendar.dataSource = self
    FSCalendar.delegate = self

    // For UITest
    self.FSCalendar.accessibilityIdentifier = "calendar"
    self.TableView.rowHeight = 40.0

}`

I also connected them in the storyboard by dragging the data source & delegate to the viewcontroller. Any ideas?

I'm also facing the same problem even I declared delegate/data source. See below,
Stack Trace:
Uncaught exception: CALayer position contains NaN: [160 nan]
libc++abi.dylib: terminate_handler unexpectedly threw an exception.
Any help?

If you get an exeption with 'CALayerInvalidGeometry', you need to implement the following delegate method:
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated;
In my case, I change a layout constraint for the calendar height:

 func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
        self.calendarHeightConstraint.constant = bounds.height
        self.view.layoutIfNeeded()
    }

This is still happening on the latest version.

EDIT:

After doing my research and playing with the code for a while, I've found that the only working solution (that I've found) is to create the calendar via Interface Builder (Storyboard/ViewController) and handling the size changes with a constraint created via IBOutlet. This way, everything works as expected. I'd like to achieve this programmatically, but this is OK (for now).

I hope this helps. Regards and happy coding.鉁岋笍

OLD:
Same problem here. I've configured the delegate and the data source, as well as the delegate method mentioned by @MintBerryCrunch.

Here's my call stack:

`* Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [187.5 nan]'
*
First throw call stack:
(

0   CoreFoundation                      0x00000001084401bb __exceptionPreprocess + 331
1   libobjc.A.dylib                     0x00000001079de735 objc_exception_throw + 48
2   CoreFoundation                      0x0000000108440015 +[NSException raise:format:] + 197
3   QuartzCore                          0x000000010ee331a3 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 141
4   QuartzCore                          0x000000010ee22293 -[CALayer setPosition:] + 57
5   QuartzCore                          0x000000010ee229ef -[CALayer setFrame:] + 561
6   UIKitCore                           0x0000000111d1f086 -[UIView(Geometry) setFrame:] + 336
7   UIKitCore                           0x0000000111cb3247 -[UIScrollView setFrame:] + 161
8   UIKitCore                           0x00000001110a43ac -[UICollectionView setFrame:] + 524
9   FSCalendar                          0x000000010719e859 -[UIView(FSCalendarExtensions) setFs_top:] + 281
10  FSCalendar                          0x00000001071ac8cf -[FSCalendarTransitionCoordinator performPathAnimationWithProgress:] + 783
11  FSCalendar                          0x00000001071a8a2e -[FSCalendarTransitionCoordinator scopeTransitionDidUpdate:] + 1134
12  FSCalendar                          0x00000001071a7a79 -[FSCalendarTransitionCoordinator handleScopeGesture:] + 185
13  FSCalendar                          0x000000010718102e -[FSCalendar handleScopeGesture:] + 158
14  UIKitCore                           0x000000011142bb81 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
15  UIKitCore                           0x0000000111434a5f _UIGestureRecognizerSendTargetActions + 109
16  UIKitCore                           0x0000000111432244 _UIGestureRecognizerSendActions + 305
17  UIKitCore                           0x000000011143149c -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 858
18  UIKitCore                           0x0000000111422f20 _UIGestureEnvironmentUpdate + 1329
19  UIKitCore                           0x00000001114229ad -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 478
20  UIKitCore                           0x000000011142271d -[UIGestureEnvironment _updateForEvent:window:] + 200
21  UIKitCore                           0x000000011189278a -[UIWindow sendEvent:] + 4058
22  UIKitCore                           0x0000000111870394 -[UIApplication sendEvent:] + 352
23  UIKitCore                           0x00000001119455a9 __dispatchPreprocessedEventFromEventQueue + 3054
24  UIKitCore                           0x00000001119481cb __handleEventQueueInternal + 5948
25  CoreFoundation                      0x00000001083a5721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
26  CoreFoundation                      0x00000001083a4f93 __CFRunLoopDoSources0 + 243
27  CoreFoundation                      0x000000010839f63f __CFRunLoopRun + 1263
28  CoreFoundation                      0x000000010839ee11 CFRunLoopRunSpecific + 625
29  GraphicsServices                    0x000000010d8c61dd GSEventRunModal + 62
30  UIKitCore                           0x000000011185481d UIApplicationMain + 140
31  [APP NAME]                          0x0000000106ac06a7 main + 71
32  libdyld.dylib                       0x000000010b059575 start + 1
33  ???                                 0x0000000000000001 0x0 + 1

)
libc++abi.dylib: terminating with uncaught exception of type NSException`

The same issue was coming with me on my project . but it is very Simple issue. we just forgot to set delegate and datasource of FSCalendar. it will not come if you set delegate and datasource of FSCalendar.

Was this page helpful?
0 / 5 - 0 ratings