Skip to content

Commit

Permalink
Merge pull request BradLarson#1037 from iamcam/master
Browse files Browse the repository at this point in the history
Prevent CGContextDrawImage error when empty images are passed to GPUImagePicture init
  • Loading branch information
BradLarson committed Jun 25, 2013
2 parents aad15fb + 6b3ddd9 commit 58c7375
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 58c7375

Please sign in to comment.