darren2005 0 Junior Poster in Training

Hi, I seem to get an Assertion failure with the following code:

if (Butten.tag==1) {
        //int errorCount = 0;
        //UIImage *filterImage;
        GPUImageAmatorkaFilter *ColorMatrix=[[GPUImageAmatorkaFilter alloc]init];
        [ColorMatrix prepareForImageCapture];
        UIImage *filterImage=[ColorMatrix imageByFilteringImage:img_MainImage];

        //while (! (filterImage = [ColorMatrix imageByFilteringImage:img_MainImage]) ) {
         //   ++errorCount;
        //}

        //if (errorCount > 0) {
            //NSLog(@"GPUImageiOSBlurFilter imageByFilteringImage button clicked:");
        //}
        vw_MainImage.image=filterImage;
        image_Edited =filterImage;
        lbl_MenuType.text=[arr_Effectname objectAtIndex:0];
        filterImage=nil;
        free((__bridge void *)(filterImage));
    }

Error is:

Assertion failure in -[GPUImagePicture initWithCGImage:smoothlyScaleOutput:removePremultiplication:], /Users/darrenedwards/Desktop/app/Source/iOS/GPUImagePicture.m:94

Line 94 is:

NSAssert( widthOfImage > 0 && heightOfImage > 0, @"Passed image must not be empty - it should be at least 1px tall and wide");

I am new to iOS development and was wondering where I would start to resolve this? How can i make sure the image is not empty or at least a size above 0px?

Dani AI

Generated

Note for : that assertion means GPUImage tried to read the pixel width/height of the image and got 0. GPUImagePicture reads the underlying CGImage width/height, so the usual causes are: the UIImage you pass is nil, its CGImage is NULL (UIImage backed only by a CIImage), or the image really has zero pixels.

Quick checks to run before filtering:

NSLog(@"img: %@, size: %.0fx%.0f, CGImage: %p", img_MainImage,
      img_MainImage.size.width, img_MainImage.size.height, img_MainImage.CGImage);

if (!img_MainImage || img_MainImage.size.width <= 0 || img_MainImage.size.height <= 0) {
    // abort — image isn't valid for GPUImage
}

If the log shows a non‑nil UIImage but CGImage is NULL and CIImage is present, convert it to a CGImage-backed UIImage first:

if (!img_MainImage.CGImage && img_MainImage.CIImage) {
    CIContext *ctx = [CIContext contextWithOptions:nil];
    CGImageRef cg = [ctx createCGImage:img_MainImage.CIImage fromRect:img_MainImage.CIImage.extent];
    img_MainImage = [UIImage imageWithCGImage:cg scale:img_MainImage.scale orientation:img_MainImage.imageOrientation];
    CGImageRelease(cg);
}

Also remove any manual calls that attempt to free Objective‑C objects (manually calling C free on an Objective‑C pointer is incorrect and unsafe). Under ARC you only need to drop references (set to nil) or let scope end.

Checklist: confirm the UIImage is not nil, confirm it has a valid CGImage and nonzero width/height, convert CIImage->CGImage if needed, and remove any incorrect manual memory frees. After those fixes, the GPUImage assertion should stop occurring.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.