Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null Graphics Context

Here is a code excerpt I am using:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^
{

    UIGraphicsBeginImageContextWithOptions(irect.size, YES, 0.0 );
    CGContextRef context = UIGraphicsGetCurrentContext();
    if (context == 0)
        NSLog (@"Null Graphics Context") ;
    else
        NSLog (@"OK") ;

    . . . .
    // Various drawing functions

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
  }) ;

I am finding that every other call to UIGraphicsGetCurrentContext is returning NULL. I get this message on the console.

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.

What would cause UIGraphicsGetCurrentContext to return an invalid graphic context?

like image 537
user3344003 Avatar asked Dec 04 '22 06:12

user3344003


1 Answers

As suggested by the comment, the answer is that the CGRect passed to UIGraphicsBeginImageContextWithOptions has zero area. That apparently cases it to fail to create a graphics context.

like image 129
user3344003 Avatar answered Dec 23 '22 14:12

user3344003