使用混合滤镜时GPUImage崩溃(“释放帧缓冲区") [英] GPUImage crash ('over release framebuffer') when using Blend Filter
问题描述
由于尝试将Blend滤镜应用于图像并显示它时发生的崩溃,我感到头疼. 我想要做的就是简单地将覆盖图像放置到另一幅图像上.
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.
这是我的代码:
- (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:
由于未捕获的异常而终止应用程序 "NSInternalInconsistencyException",原因:试图过分释放 帧缓冲区,您是否忘了调用-useNextFrameForImageCapture 在使用-imageFromCurrentFramebuffer之前?'
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?'
我确实在混合滤镜上调用了"useNextFrameForImageCapture",所以我的代码出了什么问题?
I do call 'useNextFrameForImageCapture' on blend filter so what's wrong with my code?
推荐答案
啊,我发现了导致崩溃的原因.
Argh, I found out what caused the crash.
请注意,我没有对noisePicture对象做任何强引用. 替换:
Notice that I don't keep any strong reference to the noisePicture object. Replacing:
GPUImagePicture *noisePicture
使用
@property (nonatomic, strong) GPUImagePicture *noisePicture;
...
self.noisePicture = ...
解决了该问题.感谢帮助! :)
fixed the issue. Thanks for help! :)
这篇关于使用混合滤镜时GPUImage崩溃(“释放帧缓冲区")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!