Search code examples
iosobjective-cgpuimage

GPUImage on iOS project: CVPixelBufferCreate error.


I'm trying to use this awesome library, but I'm having a problem and I can't fix it. I've spent the last 5 hours trying to but I'm completely out of ideas.

I added the library using CocoaPods and it gave me an error, so I added it as an static library (thinking off the problem was related to something related to the library integration) and also I can't make it work, I'm having the same error. I'm trying to apply a custom filter. This is my apply custom filter method:

- (id) applyLookupImage:(NSString*) filename
{
    UIImage *filteredimage = [self duplicate];

    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:filteredimage];
    GPUImagePicture *lookupImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:filename]];
    GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init];
    [stillImageSource addTarget:lookupFilter];
    [lookupImageSource addTarget:lookupFilter];

    [stillImageSource processImage];
    [lookupImageSource processImage];
    [lookupFilter imageFromCurrentFramebuffer];
    filteredimage = [lookupFilter imageFromCurrentFramebuffer];

    return filteredimage;
}

After the execution of this method I get the following error:

FBO size: 0.000000, 0.000000 2014-05-27 17:51:33.507 * Assertion failure in -[GPUImageFramebuffer generateFramebuffer] /GPUImage/framework/Source/GPUImageFramebuffer.m:156

And this is the line where the exception raises:

CVReturn err = CVPixelBufferCreate(kCFAllocatorDefault, (int)_size.width, (int)_size.height, kCVPixelFormatType_32BGRA, attrs, &renderTarget);
if (err)
{
    NSLog(@"FBO size: %f, %f", _size.width, _size.height);
    NSAssert(NO, @"Error at CVPixelBufferCreate %d", err);
}

I'm on xCode5.1

Any idea?!?!

Thanks!


Solution

  • If you're using the latest version of the framework, you're missing a

    [lookupFilter useNextFrameForImageCapture];
    

    right after the line

    [lookupImageSource addTarget:lookupFilter];
    

    You need that for -imageFromCurrentFramebuffer to return a non-nil value. That call triggers the retention of the backing framebuffer for that filter during image capture, otherwise the framebuffer for that filter will be immediately returned to the cache.

    Also, make sure that both of your input UIImages are not nil and that that have non-zero dimensions.