Crash occurring because "CALayer bounds contains NaN: [nan 0; nan 15.1]"
cocoa-touch, ios, iphone
Solution
[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`.
Problem
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?