我收到此错误:
***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'试图过度发布a framebuffer,你忘了调用-useNextFrameForImageCapture吗? 在使用-imageFromCurrentFramebuffer?'
之前
当我将滤镜应用于这样的图像时,不会发生此错误:
的ViewController
self.editImageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - bgPadding, self.view.frame.size.width - bgPadding)];
[self.editImageView setCenter:[self makeCenterWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - self.toolBar.frame.size.height)]];
[self.editImageView setBackgroundColor:[UIColor clearColor]];
[self.editImageView setContentMode:UIViewContentModeScaleAspectFit];
[self.editImageView setBackgroundColorRed:0 green:0 blue:0 alpha:0];
[self.view addSubview:self.editImageView];
FirstFilter *filter = [[FirstFilter alloc] init];
[filter imageWithFilter:0.15f inputImage:self.editImage imageView:self.editImageView];
FirstFilter.m
-(void)imageWithFilter:(float)value inputImage:(UIImage *)image imageView:(GPUImageView *)gpuImageView
{
//background picture setup
backgroundPicture = [[GPUImagePicture alloc] initWithImage:image smoothlyScaleOutput:YES];
gaussianBlurFilter = [[GPUImageGaussianBlurFilter alloc] init];
[gaussianBlurFilter setBlurRadiusInPixels:1.0f];
opacityFilter = [[GPUImageOpacityFilter alloc] init];
[opacityFilter setOpacity:0.1f];
[backgroundPicture addTarget:gaussianBlurFilter];
[gaussianBlurFilter addTarget:opacityFilter];
//yellow picture setup
GPUImagePicture *yellowPicture = [[GPUImagePicture alloc] initWithImage:[self imageFromColor:[UIColor colorWithRed:247.0f/255.0f green:209.0f/255.0f blue:148.0f/255.0f alpha:0.7f]] smoothlyScaleOutput:NO];
//red picture setup
GPUImagePicture *redPicture = [[GPUImagePicture alloc] initWithImage:[self imageFromColor:[UIColor colorWithRed:225.0f/255.0f green:49.0f/255.0f blue:90.0f/255.0f alpha:0.15f]] smoothlyScaleOutput:NO];
//blend setup
softlightBlendFilter = [[GPUImageSoftLightBlendFilter alloc] init];
GPUImageSoftLightBlendFilter *softBlend = [[GPUImageSoftLightBlendFilter alloc] init];
//blend
sourcePicture = [[GPUImagePicture alloc] initWithImage:image smoothlyScaleOutput:YES];
[sourcePicture addTarget:softlightBlendFilter];
[yellowPicture addTarget:softlightBlendFilter];
[softlightBlendFilter addTarget:softBlend];
[redPicture addTarget:softBlend];
[softBlend useNextFrameForImageCapture];
GPUImageView *imageView = (GPUImageView *)gpuImageView;
[softBlend addTarget:imageView];
[sourcePicture processImage];
[backgroundPicture processImage];
[yellowPicture processImage];
[redPicture processImage];
}
但是,当我从其他地方拨打imageWithFilter:inputImage:imageView:
时,应用程序会崩溃并出错?像这样......
//mainContainerButton is a UIButton
GPUImageView *imageView = [[GPUImageView alloc] initWithFrame:mainContainerButton.frame];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[imageView setBackgroundColor:[UIColor clearColor]];
[imageView setBackgroundColorRed:0 green:0 blue:0 alpha:0];
[mainContainerButton addSubview:imageView];
FirstFilter *filter = [[FirstFilter alloc] init];
[filter imageWithFilter:0.15f inputImage:(UIImage *)[contentArray objectAtIndex:i] imageView:(GPUImageView *)imageView];
我还尝试在GPUImageFramebuffer.m
中评论这行代码,并且没有发生崩溃,我通过过滤器获取了我的图像。
NSAssert(framebufferReferenceCount > 0, @"Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?");
我的代码中遗漏了什么?