How to detect where NaN is passing to CoreGraphics API on Mac OS X 10.9

限于喜欢 提交于 2019-12-04 07:48:59

问题


I have very large graphic Mac app and now I receive a lot of the following messages in Console on 10.9 GM.

<Error>: Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API. This is a serious error and contributes to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

I noticed that these messages appear in debugger after calling [NSApp nextEventMatchingMask: untilDate inMode: dequeue] but I think the reasons are in some other places. But I have too many places where I use Cocoa Graphics. I didn't receive this kind of message before 10.9.

How to detect where NaN is passing to CoreGraphics API?


回答1:


After much digging around, I've found you can set a symbolic breakpoint on "CGPostError" in Xcode, and that will give you a stack trace.




回答2:


I was getting this error when I was foolishly retaining an NSPopover for future use.

It seems popover.showRelativeToRect(_:) is all you need to do, and then you can forget about it.




回答3:


I found the problem. It's dividing by zero at some point that leads to NSAffineTransform with NaN elements in the matrix. For some reasons compiler and OS passed this situation before 10.9.




回答4:


so you should get an exception at that point, so an exception breakpoint should work...

here are things to look out for...

you may have messed up a method signature... ie

-(float)myHeight
{
    return 56.0;
}

gets messed up in a subclass

-(int)myHeight
{
    return 42;
}

or you have some bad math(s) that emit a NaN...

there are a couple of ways to detect a NaN... c99 introduced isnan()
also the ieee float trick of (f != f) will be true for NaN



来源:https://stackoverflow.com/questions/19187344/how-to-detect-where-nan-is-passing-to-coregraphics-api-on-mac-os-x-10-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!