objective-c iOS 7.0 下的无效上下文 0x0 和系统降级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19599266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
invalid context 0x0 under iOS 7.0 and system degradation
提问by ?lex
I've read as many search results I could find on this dreaded problem, unfortunatelly, each one seems to focus on a specific function call.
我已经阅读了尽可能多的关于这个可怕问题的搜索结果,不幸的是,每个搜索结果似乎都集中在一个特定的函数调用上。
My problem is that I get the same error from multiple functions, which I am guessing are being called back from functions that I use.
我的问题是我从多个函数中得到相同的错误,我猜这些函数是从我使用的函数中回调的。
To make matters worse, the actual code is within a custom private framework which is being imported in another project, and as such, debugging isn't as simple?
更糟糕的是,实际代码是在另一个项目中导入的自定义私有框架中,因此,调试不是那么简单?
Can anyone point me to the right direction? I have a feeling I'm calling certain methods wrongly or with bad context, but the output from xcode is not very helpful at this point.
任何人都可以指出我正确的方向吗?我有一种感觉,我错误地或上下文不好地调用了某些方法,但此时 xcode 的输出并不是很有帮助。
: CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextSetFlatness: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextGetBlendMode: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing 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.
: CGContextSetFillColorWithColor: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextSetStrokeColorWithColor: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
CGContextSaveGState:无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextSetFlatness: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextAddPath: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextDrawPath: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextRestoreGState: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
: CGContextGetBlendMode: 无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是一种礼貌:请解决此问题。在即将到来的更新中,这将成为致命错误。
Those errors may occur when a custom view is presented, or one of its inherited classes. At which point they spawn multiple times, until the keyboard won't provide any input. Touch events are still registered, but system slows down, and eventually may lead to unallocated object errors.
当显示自定义视图或其继承的类之一时,可能会发生这些错误。此时它们会生成多次,直到键盘不提供任何输入。触摸事件仍会被注册,但系统会变慢,最终可能会导致未分配的对象错误。
EDIT #1:I do have access to the framework being imported, but I do not see anything weird in the classes which causing the issue.
编辑 #1:我确实可以访问正在导入的框架,但我在导致问题的类中没有看到任何奇怪的东西。
EDIT #2:I just received an email that iOS 7.1 has been released for developers. I'm curious to see if this goes away, or become worse, or can be solved.
编辑 #2:我刚刚收到一封电子邮件,说 iOS 7.1 已经发布给开发者。我很想知道这是否会消失,或者变得更糟,或者可以解决。
采纳答案by bilobatum
Others will ask you to post the code where you access a core graphics context, but I doubt that's the issue. These invalid context 0x0 error messages are common and easy to reproduce in iOS 7. In fact, I can reproduce the error using storyboard with zero code. I drag a UITextField onto the canvas in IB, run the app, and double tap inside the text field.
其他人会要求您发布访问核心图形上下文的代码,但我怀疑这就是问题所在。这些无效的上下文 0x0 错误消息在 iOS 7 中很常见并且很容易重现。实际上,我可以使用零代码的 storyboard 重现错误。我将一个 UITextField 拖到 IB 的画布上,运行应用程序,然后在文本字段内双击。
In many situations, it's hard for me to take the invalid context 0x0 error messages seriously. I don't know if your situation warrants greater concern (I agree with Rob Napier that it's worth investigating, especially if you are explicitly using a graphics context).
在许多情况下,我很难认真对待无效上下文 0x0 错误消息。我不知道您的情况是否值得更多关注(我同意 Rob Napier 的观点,即值得调查,尤其是当您明确使用图形上下文时)。
In my own projects, I'm hoping that many of these errors magically disappear some day (but that day did not come with 7.0.3).
在我自己的项目中,我希望这些错误中的许多有朝一日能神奇地消失(但 7.0.3 并没有出现这一天)。
Update:After installing Xcode 5.1 and targeting iOS 7.1, I can no longer reproduce the error by double tapping inside an empty text field.
更新:安装 Xcode 5.1 并针对 iOS 7.1 后,我无法再通过在空文本字段中双击来重现错误。
回答by Art Gillespie
If you're curious what code is causing these logs, you can add a symbolic breakpointon CGPostError.
如果你想知道什么样的代码是导致这些日志,你可以添加一个象征性的断点上CGPostError。
回答by Rob
These sorts of errors are historically the result of calling Core Graphics functions when not within a context that is established within drawRector between calls like UIGraphicsBeginImageContextand UIGraphicsEndImageContext(or other UIKit functions like that which begin and end a context).
从历史上看,这些类型的错误是在不在drawRect诸如UIGraphicsBeginImageContextand 之类的调用UIGraphicsEndImageContext(或其他 UIKit 函数,例如开始和结束上下文)之内或之间建立的上下文中时调用 Core Graphics 函数的结果。
Having said that, though, bilobatum is correct that this particular sequence of errors can be a result of that iOS 7 bug he references in his answer. If not seeing these errors in your iOS6 targets, or if after a quick scan of this private framework you don't find any suspect Core Graphics calls, it may just be this iOS 7 bug. Good catch, bilobatum!
尽管如此,bilobatum 是正确的,这个特定的错误序列可能是他在回答中引用的那个 iOS 7 错误的结果。如果在你的 iOS6 目标中没有看到这些错误,或者如果在快速扫描这个私有框架后你没有发现任何可疑的 Core Graphics 调用,它可能只是这个 iOS 7 错误。好收获,双叶豆!
回答by lbsweek
UIGraphicsBeginImageContext( size );
CGContextRef context = UIGraphicsGetCurrentContext();
make sure the size.width or size.height is not 0,
确保 size.width 或 size.height 不为 0,
you can add symbol breakpoint to CGPostError to check
您可以将符号断点添加到 CGPostError 以进行检查
回答by Kevin Delord
I had this problem with a simple UITextField (keyboard not showing up and many different invalid context error messages on the console). I just find a workaround by looking to another problem on SO: Cannot find executable for CFBundle CertUIFramework.axbundle
我在一个简单的 UITextField 上遇到了这个问题(键盘没有显示,控制台上有许多不同的无效上下文错误消息)。我只是通过查看 SO 上的另一个问题找到了一种解决方法:找不到 CFBundle CertUIFramework.axbundle 的可执行文件
Just do:
做就是了:
click on iOS Simulator > Reset Content and Settings... and run again.
单击 iOS 模拟器 > 重置内容和设置...并再次运行。
The problem shouldn't be there anymore
问题应该不存在了
回答by Denis Kozhukhov
In my case i've got these errors in this code:
就我而言,我在这段代码中遇到了这些错误:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
UIBezierPath *path;
path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(size*2, 0)];
[path addLineToPoint:CGPointMake(size, size*2)];
[path closePath];
[path fill];
shapeLayer.path = path.CGPath;
shapeLayer.strokeColor = [[UIColor blackColor] CGColor];
shapeLayer.fillColor = color;
shapeLayer.lineWidth = width;
[self addSublayer:shapeLayer];
after some thoughts and test I detect the problem - it was this call:
经过一些思考和测试后,我发现了问题——是这个电话:
[path fill];
as I detect - in my code this call is not necessary, because of filling will be done by other way - so I simply remove it.
正如我所检测到的 - 在我的代码中,这个调用不是必需的,因为填充将通过其他方式完成 - 所以我只是将其删除。
回答by David Roop
I had this same issue and I forgot to import QuartzCore/QuartzCore.h, This solved my issue with these errors.
我遇到了同样的问题,但忘记导入 QuartzCore/QuartzCore.h,这解决了我的这些错误问题。
#import <QuartzCore/QuartzCore.h>
回答by David Roop
Straight Answer :The problem is because you have used Core graphics elements like CGContext etc in other than - (void)drawRect:(CGRect)rectthis method.
直接回答:问题是因为您在- (void)drawRect:(CGRect)rect此方法之外使用了诸如 CGContext 等核心图形元素。
Now kindly move your code to this method. And it will strop giving you warnings/Errors.
现在请将您的代码移至此方法。它会停止给你警告/错误。
回答by Collin
I was getting this error because I was using a UIColor object as an attribute in an NSAttributedString dictionary that was being used in a CATextLayer object. I changed the dictionary to hold a CGColorRef and the error went away.
我收到此错误是因为我在 CATextLayer 对象中使用的 NSAttributedString 字典中使用 UIColor 对象作为属性。我更改了字典以保存 CGColorRef 并且错误消失了。
[wordAttributes setObject:(id)[UIColor whiteColor].CGColor forKey:(NSString*)kCTForegroundColorAttributeName];
回答by Nagarjun
In some cases you may need to include the line #import <QuartzCore/QuartzCore.h>.
在某些情况下,您可能需要包含该行#import <QuartzCore/QuartzCore.h>。

