GPUImage crash ('over release framebuffer') when using Blend Filter

只谈情不闲聊 提交于 2019-12-11 03:12:14

问题


I'm getting a headache because of the crash I experience when trying to apply Blend filter to an image and displaying it. What I want to do is simply put an overlay image onto another image.

Here's my code:

- (GPUImageOutput<GPUImageInput> *)myFilter
{
    GPUImageFilterGroup *filtersGroup = [GPUImageFilterGroup new];

    // Saturation
    GPUImageSaturationFilter *saturationFilter = [GPUImageSaturationFilter new];
    saturationFilter.saturation = 0.0;
    [filtersGroup addFilter:saturationFilter];

    // Noise
    UIImage *noiseImage = [UIImage imageNamed:@"noise.png"];
    GPUImagePicture *noisePicture = [[GPUImagePicture alloc] initWithImage:noiseImage];
    GPUImageAddBlendFilter *blend = [GPUImageAddBlendFilter new];
    [blend useNextFrameForImageCapture];
    [filtersGroup addFilter:blend];
    [noisePicture addTarget:blend atTextureLocation:1];
    [noisePicture processImage];

    [saturationFilter addTarget:blend];

    filtersGroup.initialFilters = @[saturationFilter];
    filtersGroup.terminalFilter = blend;

    return filtersGroup;
}


    // Applying filter
    GPUImageOutput <GPUImageInput> *effect = [self myFilter];
    self._photoHandle = [[GPUImagePicture alloc] initWithImage:staticImage];
    [self._photoHandle addTarget:effect];
    [effect addTarget:self.targetPreviewView];
    [self._photoHandle processImage]; // Crash

When I try to run it, app crashes and I get this message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?'

I do call 'useNextFrameForImageCapture' on blend filter so what's wrong with my code?


回答1:


Argh, I found out what caused the crash.

Notice that I don't keep any strong reference to the noisePicture object. Replacing:

GPUImagePicture *noisePicture

with

@property (nonatomic, strong) GPUImagePicture *noisePicture;
...
self.noisePicture = ...

fixed the issue. Thanks for help! :)



来源:https://stackoverflow.com/questions/24395093/gpuimage-crash-over-release-framebuffer-when-using-blend-filter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!