Reputation: 14527
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?
Upvotes: 15
Views: 18772
Reputation: 49
The codes below had helped me in my case.
super.init(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
Please ensure that your CGRect and other Child of UIView size which are passed works properly and have the right values. and Don't forget to turn your Exception debugging modes on.
Upvotes: 0
Reputation: 46703
You can set the CG_NUMERICS_SHOW_BACKTRACE
environmental variable in the Xcode run scheme and it will dump the stacktrace that caused the non-numeric value to occur.
From there, just investigate why it's happening and guard against it.
Upvotes: 3
Reputation: 4314
I know you have already found the problem but for those who are facing with the same problem :
I had the same problem. My code was:
CGRect rect;
rect.size.width = _mImage.size.width;
rect.size.height = _mImage.size.height;
[_imageView setFrame:rect];
When I open the view for the first and second time everything was working fine. But in the third try on the like [_imageView setFrame:rect]
I had CALayer bounds contains NaN
So I manually added x
and y
for my rect
:
rect.origin.x = 0;
rect.origin.y = 0;
So it's working fine now.
Upvotes: 0
Reputation: 3480
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.
Upvotes: 2
Reputation: 69
Guys! My case was not like this, but close. I've got Nan values in frame rect when I was trying to make UIimageView. After some searches I figured out that I was initializing frame from nothing - I binded frame to UIimage size, but didn't check if image is not nil. So that's why Nan values appeared in my case. Check if you pass all values correctly before creating frame from them.
Upvotes: 1
Reputation: 119031
[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
.
Upvotes: 10