GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Crash after calling capturePhotoAsImage* with Front Facing Camera

Open powellmark opened this issue 14 years ago • 20 comments

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:

  1. Default back facing camera - No crash
  2. Switch to front facing camera - Crash
  3. Switch to front facing camera then back to the back facing camera - No crash.
  4. Start the app in front facing camera mode - Crash.

Typical FilterFBOofSize errors means that it's not getting an image. Any ideas?

powellmark avatar Sep 06 '12 19:09 powellmark

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.

powellmark avatar Sep 06 '12 19:09 powellmark

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.

powellmark avatar Sep 06 '12 19:09 powellmark

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.

BradLarson avatar Sep 06 '12 19:09 BradLarson

This crash occurs while starting with the Front Facing camera. So, multiple frames are captured.

powellmark avatar Sep 06 '12 19:09 powellmark

+1, crashing when trying to capture a photo from the front facing camera

rromanchuk avatar Sep 12 '12 13:09 rromanchuk

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?

Division avatar Sep 29 '12 15:09 Division

My workaround was the remove the included "workaround". See above.

powellmark avatar Sep 29 '12 15:09 powellmark

Thanks a lot! Doesn't crash now. Have you got any corrupt images after that?

Division avatar Sep 29 '12 16:09 Division

+1 on this issue. @BradLarson any plans on a fix?

tomasikp avatar Nov 27 '12 07:11 tomasikp

@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.

balabs avatar Nov 27 '12 19:11 balabs

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 avatar Nov 27 '12 19:11 powellmark

@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.

balabs avatar Nov 27 '12 19:11 balabs

+1 @powellmark workaround is fine

rromanchuk avatar Nov 27 '12 21:11 rromanchuk

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.

BradLarson avatar Nov 28 '12 01:11 BradLarson

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

dreamolight avatar Feb 09 '13 12:02 dreamolight

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??

jadelmag avatar Mar 14 '13 22:03 jadelmag

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]; }

dreamolight avatar Mar 15 '13 05:03 dreamolight

Thanks!! I used this method but i change filter capture photo without time for capture wright and i solved the problem :D

jadelmag avatar Mar 15 '13 15:03 jadelmag

Glad it helps

dreamolight avatar Mar 16 '13 12:03 dreamolight

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:

image_corruption

// 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])

nuudles avatar Mar 16 '13 17:03 nuudles