Skip to content

Commit 6b3ddd9

Browse files
author
Cameron N Perry
committed
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:: "<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.
1 parent 6921f09 commit 6b3ddd9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

framework/Source/iOS/GPUImagePicture.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ - (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoot
6767
// TODO: Dispatch this whole thing asynchronously to move image loading off main thread
6868
CGFloat widthOfImage = CGImageGetWidth(newImageSource);
6969
CGFloat heightOfImage = CGImageGetHeight(newImageSource);
70+
71+
// 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
72+
if( !(widthOfImage >= 1) || !(heightOfImage >= 1) ){
73+
widthOfImage = heightOfImage = 2.0;
74+
UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthOfImage, heightOfImage), NO, 0.0);
75+
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
76+
UIGraphicsEndImageContext();
77+
newImageSource = blank.CGImage;
78+
blank = nil;
79+
}
80+
7081
pixelSizeOfImage = CGSizeMake(widthOfImage, heightOfImage);
7182
CGSize pixelSizeToUseForTexture = pixelSizeOfImage;
7283

0 commit comments

Comments
 (0)