空图形上下文

use*_*003 4 ios uigraphicscontext

这是我正在使用的代码摘录:

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();
  }) ;
Run Code Online (Sandbox Code Playgroud)

我发现每次调用UIGraphicsGetCurrentContext都会返回NULL.我在控制台上收到此消息.

CGContextRestoreGState:无效的上下文0x0.这是一个严重的错误.该应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降低.此通知是礼貌的:请解决此问题.它将成为即将到来的更新中的致命错误.

什么会导致UIGraphicsGetCurrentContext返回无效的图形上下文?

use*_*003 16

正如评论所建议的那样,答案是CGRect传递给UIGraphicsBeginImageContextWithOptions零区域.显然,它无法创建图形上下文.