这是我正在使用的代码片段:
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();
}) ;
我发现每隔一次调用UIGraphicsGetCurrentContext就会返回NULL。我在控制台上看到了这个消息。
CGContextRestoreGState: invalid context 0x0. 这是一个严重的错误。这个应用程序或它使用的库正在使用一个无效的上下文,从而对系统稳定性和可靠性造成了总体的损害。这个通知是出于礼貌,请解决这个问题。它将在即将发布的更新中变成致命错误。
什么原因会导致UIGraphicsGetCurrentContext返回无效的图形上下文?