Crash after calling capturePhotoAsImage* with Front Facing Camera
I'm using a GPUStillCamera, I added a button to toggle the active camera (front/back). The output view works well, switching the input applying filters, etc. However, as soon as I try to take a picture it crashes with Assertion failure in -[GPUImageSaturationFilter createFilterFBOofSize:] (Saturation Filter being the filter I pass into the call).
It only crashes with the front facing camera. So:
- Default back facing camera - No crash
- Switch to front facing camera - Crash
- Switch to front facing camera then back to the back facing camera - No crash.
- Start the app in front facing camera mode - Crash.
Typical FilterFBOofSize errors means that it's not getting an image. Any ideas?
Tracing through the debugger I hit:
AVCaptureDevicePosition currentCameraPosition = [[videoInput device] position];
if ( (currentCameraPosition != AVCaptureDevicePositionFront) || (![GPUImageOpenGLESContext supportsFastTextureUpload]))
{
dispatch_semaphore_signal(frameRenderingSemaphore);
[self captureOutput:photoOutput didOutputSampleBuffer:imageSampleBuffer fromConnection:[[photoOutput connections] objectAtIndex:0]];
dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_FOREVER);
}
current camera position does equal front and apparently supports fast texture update is true. So, that block is skipped. Therefore, a call to [self captureOutput] is never made, then it goes on to process a non-existant image.
Removing that if statement solves my issue. I see the comment of:
// This is a workaround for the corrupt images that are sometimes returned when taking a photo with the front camera and using the iOS 5.0 texture caches
However, that workaround seems to create more issues than it solves.
That workaround assumes that there will have been a previous frame from the video preview on the front camera, so it works well when the front camera has been running for at least one frame. If you're switching, then immediately capturing a photo, that will not be the case and you'll get a null frame being passed in there.
That case still needs to be in there for the image corruption that you'll see from the front camera with still photos. To deal with this, you could insert a short delay between switching to the front camera and actually grabbing a photo from it. This would allow one or more preview frames to work their way through the pipeline before you grab the photo and avoid this null framebuffer issue. You could also manually disable the texture caches, but that would have adverse effects on your photo capture performance and memory usage.
This crash occurs while starting with the Front Facing camera. So, multiple frames are captured.
+1, crashing when trying to capture a photo from the front facing camera
Same issue - crashing with front camera [GPUImageFilter createFilterFBOofSize:] NSAssert(status == GL_FRAMEBUFFER_COMPLETE, @"Incomplete filter FBO: %d", status);
Could you please fix it or advise workaround?
My workaround was the remove the included "workaround". See above.
Thanks a lot! Doesn't crash now. Have you got any corrupt images after that?
+1 on this issue. @BradLarson any plans on a fix?
@powellmark Have used your Workaround by deleting the if statement from "workaround". I wonder what are the consequences? Are there some critical bugs or side-effects? I can tell that I could not take a photo with front camera, but now it is possible.
I have not witnessed any issues removing the workaround. Additionally, this was done 3 months ago and the app has gone through extensive testing and nothing odd that I would attribute to this has been seen.
@powellmark Thanks a lot for posting this as solution, I was starting to lose my patience, I have lost two days already on this issue. And once again thanks for fast response.
+1 @powellmark workaround is fine
Just be aware that removing the workaround I put into place for the front-facing camera will result in corrupt images being captured on iOS 5.x. 6.x is fine, but there's a bug in the texture cache implementation in 5.x that will be triggered if you do this.
I agree that a more reliable solution needs to be found, but I haven't worked on this part of the framework in weeks, and am out of town for work over the next two weeks. I don't know if I'd be able to work on this before January, due to my time commitments elsewhere. Someone else will need to come up with a better solution.
I have the same issue,but it crashes at Line 187 in GPUImageFilter.m CFRetain(renderTarget);
renderTarget is NULL here,CFRelase with NULL would make app crash,but when I set breakpoint at renderTarget=NULL,and this breakpoint wouldn't be triggered,so I was wondering why the renderTarget became NULL
I have the same issue that dreamolight CFRetain(renderTarget); renderTarget is NULL when i take a photo with frontal camera using ios 6. Is solved??
I captured via Front Camera without crash by delayed capture
-
(void)delayedCapture:(GPUImageOutput
*)capture{ [imageCamera capturePhotoAsImageProcessedUpToFilter:capture withCompletionHandler:^(UIImage *processedImage, NSError *error){ [self showEditImage:processedImage]; [imageCamera stopCameraCapture]; [imageCamera removeAllTargets]; }]; } -
(void)captureImage{ [indicator startAnimating]; indicator.hidden = NO;
[imageCamera removeAllTargets]; GPUImageOutput
*captureFilter = [[GPUImageBrightnessFilter alloc] init]; [imageCamera addTarget:captureFilter]; [self performSelector:@selector(delayedCapture:) withObject:captureFilter afterDelay:0.1]; }
Thanks!! I used this method but i change filter capture photo without time for capture wright and i solved the problem :D
Glad it helps
FYI, even with the workaround, I'm still seeing image corruption when capturing with the back camera on some devices (iPhone 4s running 5.1.1). I've attached an image to show what it looks like. I was able to resolve by not doing the front camera check:

// This is a workaround for the corrupt images that are sometimes returned when taking a photo with the front camera and using the iOS 5.0 texture caches if (![GPUImageOpenGLESContext supportsFastTextureUpload])