问题
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