From 6b3ddd9c8de20b00bfa7331fa8caed783b7dfbf6 Mon Sep 17 00:00:00 2001 From: Cameron N Perry Date: Wed, 19 Jun 2013 22:01:59 -0700 Subject: [PATCH] If GPUImagePicture is passed an empty image, create a small 2x2 image to prevent a possibly fatal error on CGContextDrawImage The empty image passed to GPUImagePicture will trigger this error when CGContextDrawImage is called on init:: ": CGContextDrawImage: 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." This should prevent the error altogether. --- framework/Source/iOS/GPUImagePicture.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/framework/Source/iOS/GPUImagePicture.m b/framework/Source/iOS/GPUImagePicture.m index de7a36c9a..44e8330df 100755 --- a/framework/Source/iOS/GPUImagePicture.m +++ b/framework/Source/iOS/GPUImagePicture.m @@ -67,6 +67,17 @@ - (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoot // TODO: Dispatch this whole thing asynchronously to move image loading off main thread CGFloat widthOfImage = CGImageGetWidth(newImageSource); CGFloat heightOfImage = CGImageGetHeight(newImageSource); + + // If passed an empty image reference, create a small 2x2 image so we don't trigger a fatal error in the future on CGContextDrawImage below + if( !(widthOfImage >= 1) || !(heightOfImage >= 1) ){ + widthOfImage = heightOfImage = 2.0; + UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthOfImage, heightOfImage), NO, 0.0); + UIImage *blank = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + newImageSource = blank.CGImage; + blank = nil; + } + pixelSizeOfImage = CGSizeMake(widthOfImage, heightOfImage); CGSize pixelSizeToUseForTexture = pixelSizeOfImage;