Search code examples
iosobjective-cgpuimage

GPUImage mixing image and video getting crash overreleasing a frame buffer


I'm trying to mashup videos with videos, or videos with images, or images with images. My code works fine if I'm doing all videos or all images, however when I try and mix images with videos I get a crash on the assertion:

Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?

I've tried adding [<some_filter> useNextFrameForImageCapture] at various points throughout the code, but I can't figure out where I need to add it or if that's even my problem.

My chain is:

GPUImagePicture -> any filter     --\ 
                                      > GPUImageColorDodgeBlendFilter
GPUImageVideoCamera -> any filter --/

I've tried simplifying my filter chain for debugging and if I eliminate any middle filters then it works for all combinations of images/videos. But as soon as I add any one of the filters before the blend then it will crash.


Solution

  • It turns out this is an open bug with GPUImage. When mixing a video/camera source with a GPUImagePicture.

    I worked around it by adding:

    GPUImageNormalBlendFilter *blendFilter = [GPUImageNormalBlendFilter new];
    [videoCameras[0] addTarget:blendFilter];
    [source addTarget:blendFilter];
    

    As the first filter in the picture's chain. The video doesn't actually show up and it prevents any crashes.