Skip to content

Commit

Permalink
If GPUImagePicture is passed an empty image, create a small 2x2 image…
Browse files Browse the repository at this point in the history
… to prevent a possibly fatal error on CGContextDrawImage

The empty image passed to GPUImagePicture will trigger this error when CGContextDrawImage is called on init::

"<Error>: 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.
  • Loading branch information
Cameron N Perry committed Jun 20, 2013
1 parent 6921f09 commit 6b3ddd9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions framework/Source/iOS/GPUImagePicture.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6b3ddd9

Please sign in to comment.