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

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.


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.


[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.