Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash occurring because "CALayer bounds contains NaN: [nan 0; nan 15.1]"

I am getting the following crash:

CALayerInvalidGeometry CALayerInvalidGeometry
CALayer bounds contains NaN: [nan 0; nan 15.1]

on the last line of this code:

CGRect bounds = self.bounds;
bounds.size = CGSizeMake(fabsf(self.width), self.height);
self.bounds = bounds;

where self.width is derived from a pan gesture recognizer:

CGPoint panGestureRecognizerTranslationPoint = [panGestureRecognizer translationInView:panGestureRecognizer.view.superview.superview];

CGPoint rotatedPanGestureRecognizerTranslationPoint = CGPointApplyAffineTransform(panGestureRecognizerTranslationPoint, CGAffineTransformMakeRotation(-self.angle));
self.width += rotatedPanGestureRecognizerTranslationPoint.x;

The one commonality when I get this crash is in the error message, it's always [nan 0; followed by something. Anyone know what could be causing this?

like image 431
Ser Pounce Avatar asked Jan 06 '14 11:01

Ser Pounce


2 Answers

in my case I forgot to add images in my project and runtime I was trying to use those images by their name thats why I got this error.

Now its solved after placed the images in project.

Hope this tips helps to others.

like image 41
Muhammad Rizwan Avatar answered Sep 19 '22 23:09

Muhammad Rizwan


[nan 0; nan 15.1]

This means that the x position of the bounds and the width are both not numbers. That could mean negative values, or it could be a divide by zero type issue. nan of the width could also possibly be a very large width that can't be supported (though that should lead to other error messages).

This kind of thing will often be the result of transforms being applied, either to the values used to create the bounds or to the view / layer to which the bounds are applied (as this will modify the applied bounds to determine the frame).

With rotation transforms, be careful with the anchorPoint.

When using view / layer transforms, reset the transform to identity before making changes to the frame.

like image 139
Wain Avatar answered Sep 21 '22 23:09

Wain