Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, March 23, 2016

invalid context 0x0 under iOS 7.0 and system degradation

invalid context 0x0 under iOS 7.0 and system degradation


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.

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

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.

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.

Answer by bilobatum for invalid context 0x0 under iOS 7.0 and system degradation


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.

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

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

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.

Answer by Rob for invalid context 0x0 under iOS 7.0 and system degradation


These sorts of errors are historically the result of calling Core Graphics functions when not within a context that is established within drawRect or between calls like UIGraphicsBeginImageContext and UIGraphicsEndImageContext (or other UIKit functions like that which begin and end a context).

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!

Answer by Art Gillespie for invalid context 0x0 under iOS 7.0 and system degradation


If you're curious what code is causing these logs, you can add a symbolic breakpoint on CGPostError.

Answer by Denis Kozhukhov for invalid context 0x0 under iOS 7.0 and system degradation


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.

Answer by Kevin Delord for invalid context 0x0 under iOS 7.0 and system degradation


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:

href="http://stackoverflow.com/questions/18888059/cannot-find-executable-for-cfbundle-certuiframework-axbundle">Cannot find executable for CFBundle CertUIFramework.axbundle

Just do:

click on iOS Simulator > Reset Content and Settings... and run again.

The problem shouldn't be there anymore

Answer by jamone for invalid context 0x0 under iOS 7.0 and system degradation


I have had cases where the context returned from UIGraphicsGetCurrentContext() is NULL, and if you try using it for anything this message appears. It is the view's responsibility to push a context using UIGraphicsPushContext prior to calling drawRect:, if you call drawRect: directly instead of [view setNeedsDisplay] you risk the context not being set yet. My hunch is that prior to iOS 7 the context was pushed for the view on init, and now on iOS 7 the context isn't pushed until the first time drawRect: is about to be called. I suspect some UIKit code is calling drawRect: directly and this is why there are issues with some code even when no custom drawing is being done.

Solutions (if doing custom drawing):

  1. Don't call drawRect: directly, use [view setNeedsDisplay] or if you need immediate drawing use [view.layer draw]
  2. In your drawRect: get the context but don't use it outside the body of this if statement if (context) {}

Answer by David Roop for invalid context 0x0 under iOS 7.0 and system degradation


I had this same issue and I forgot to import QuartzCore/QuartzCore.h, This solved my issue with these errors.

    #import   

Answer by Meet for invalid context 0x0 under iOS 7.0 and system degradation


I was creating UIImage from context using below code:

      UIGraphicsBeginImageContext(size);      CGContextRef context = UIGraphicsGetCurrentContext();        CGContextSetFillColorWithColor(context, color.CGColor);      CGContextFillRect(context, (CGRect){.size = size});        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();      UIGraphicsEndImageContext();  

Thus I was getting the error.

So I removed the Derived Data content, restarted my XCode. And it worked.

Answer by Peter B. Kramer for invalid context 0x0 under iOS 7.0 and system degradation


I had this problem in a UITextField when I held the touch over a blank field with just placeholder text. I used the following work-around to eliminate blank fields:

-(void)textFieldDidBeginEditing:(UITextField *)textField{            textField.text=[@" " stringByAppendingString:textField.text];            //other stuff here  }      -(BOOL)textFieldShouldReturn:(UITextField *)textField{             if(textField.text.length>0){               if([[textField.text substringToIndex:1] isEqualToString:@" "])                   textField.text=[textField.text substringFromIndex:1];           }           //  other stuff here  }  

Answer by JuJoDi for invalid context 0x0 under iOS 7.0 and system degradation


Turning off autolayout in the affected view causes this error to go away in some cases where you're placing and moving UI elements (especially custom ones which are drawn programmatically) within a view. I was using JVFloatLabeledTextField when I discovered this symptom.

Answer by lbsweek for invalid context 0x0 under iOS 7.0 and system degradation


UIGraphicsBeginImageContext( size );  CGContextRef context = UIGraphicsGetCurrentContext();  

make sure the size.width or size.height is not 0,

you can add symbol breakpoint to CGPostError to check

Answer by Taylor Halliday for invalid context 0x0 under iOS 7.0 and system degradation


For me, the answer was that I was unnecessarily releasing the graphics context in drawRect:. Throwing a symbolic breakpoint on CGPostError pointed me to the culprit.

Answer by Daniel ?kesson for invalid context 0x0 under iOS 7.0 and system degradation


Got this error as I had set

textfield.delegate = self  

Without implementing any of the delegate routines. Removing that line solved the problem for me

Answer by Collin for invalid context 0x0 under iOS 7.0 and system degradation


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.

[wordAttributes setObject:(id)[UIColor whiteColor].CGColor forKey:(NSString*)kCTForegroundColorAttributeName];  

Answer by Nagarjun for invalid context 0x0 under iOS 7.0 and system degradation


In some cases you may need to include the line #import .

Answer by Kyle Redfearn for invalid context 0x0 under iOS 7.0 and system degradation


For me I was getting this error because I was releasing the the CGContextRef as shown below:

- (void)drawRect:(CGRect)rect  {      CGContextRef context = UIGraphicsGetCurrentContext();        // DRAW BACKGROUND CIRCLE      CGContextSetFillColorWithColor(context, [[UIColor gray] colorWithAlphaComponent:0.6].CGColor);      CGContextFillEllipseInRect(context, rect);    //    CGContextRelease(context);  }  

Removing the release solved the issue

Answer by Saleh Albuga for invalid context 0x0 under iOS 7.0 and system degradation


I got it when I mistyped the image name in activityImage method in UIActivity subclass

- (UIImage *)activityImage  {      return [UIImage imageNamed:@"img.png"];  }  

Typing the right image solved it for me.

Answer by Nagarjun for invalid context 0x0 under iOS 7.0 and system degradation


Uninstall the app from simulator and run again

Answer by Joe for invalid context 0x0 under iOS 7.0 and system degradation


I have the same problem. In my project, i have try to create a textField and add it to my pdf file. Old Code:

- (void) drawInContext:(CGContextRef)context {      //Otherwise we're upside-down      CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));        CGContextSetTextDrawingMode(context, kCGTextFill); // This is the default      [[UIColor blackColor] setFill]; // ***This is the problem ***        CGFloat x = self.rect.origin.x;      CGFloat y = self.rect.origin.y + self.font.pointSize;      [self.text drawAtPoint:CGPointMake(x, y)              withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:12]}];  }  

After solved this problem,the code changed :

old:[[UIColor blackColor] setFill];     new:CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);  

I found the solution at UIColor SetFill doesn't work. And Thanks the helper.

Answer by Joris van Liempd for invalid context 0x0 under iOS 7.0 and system degradation


In my case, disabling the "Hardware -> Connect hardware keyboard" option in the Simulator eliminated the problem, using XCode 6.1

Related Posts:

0 comments:

Post a Comment

Popular Posts

Fun Page

Powered by Blogger.