Photo saving never complete
Here is my code:
[self.stillCamera capturePhotoAsJPEGProcessedUpToFilter:self.filter withCompletionHandler:^(NSData *processedJPEG, NSError *error){ [_library writeImageDataToSavedPhotosAlbum:processedJPEG metadata:nil completionBlock:^(NSURL *assetURL, NSError *error2) { if (error2) { //save to roll }else { runOnMainQueueWithoutDeadlocking(^{ [button setEnabled:YES]; }); //NSLog(@"PHOTO SAVED - assetURL: %@", assetURL); } }]; }];
This function is from the example, the problem is, when click the button to save, most situations works fine, but sometime it just won't be saved, the block "withCompletionHandler" will never be called, and the photo is not returned.
I've tested for days, but haven't found the exact situation to reproduce this issue, but sometimes is happen after I change the position of camera, here is the code I use to change camera position:
UIButton *button = (UIButton *)sender;
button.selected = !button.isSelected;
//turn off torch when swith bettwen cameras, if it is on
if (_torchSwitch.isSelected) {
[_torchSwitch setSelected:NO];
NSError *error = nil;
if (![self.stillCamera.inputCamera lockForConfiguration:&error])
{
NSLog(@"Error locking for configuration: %@", error);
}
[self.stillCamera.inputCamera setTorchMode:AVCaptureTorchModeOff];
[self.stillCamera.inputCamera unlockForConfiguration];
}
if (button.isSelected) {
[_torchSwitch setEnabled:NO];
if(self.stillCamera.cameraPosition == AVCaptureDevicePositionBack)
[self.stillCamera rotateCamera];
}else{
[_torchSwitch setEnabled:YES];
if(self.stillCamera.cameraPosition == AVCaptureDevicePositionFront)
[self.stillCamera rotateCamera];
}
Please take a look at this issue, thanks.
I have seen a similar issue, but mine has been a little more nefarious. Most of the time it works well, but every once in awhile it will fail. The iPhone will lock up and then after a long period of non-responsiveness will restart.
I'm trying to figure out the case that triggers this to track it down.
Mark, the case you describe there is almost always due to memory exhaustion. The iPhone 4S can take gigantic photos, and every filter that processes these has at least one photo-sized framebuffer. Look for memory spikes in Memory Monitor when taking photos in your application. You might need to create custom filters that combine multiple effects in order to reduce memory pressure, among other things.
Brad, thanks, that confirms my suspicions. As a test just before I take an picture I remove ALL filters from the GPUImageStillCamera (save a default saturation) and take the picture. Then I apply the original filter chain to the processed image. This seems to work as well. However, for general performance reasons I was looking into combining filters into as few as possible. My filter chain right now is 8 filters.
This may be inappropriate for this thread, but any advice for combining filters would be appreciated (tips, etc).
Removing a filter from the chain will not free the memory of its backing framebuffer until the filter itself is deallocated, so you may not be saving much in memory consumption (particularly if the filter has most recently processed a large image).
Combining filters will require custom GLSL shader code. That's a whole topic by itself, and there are plenty of resources out there for learning OpenGL ES 2.0 GLSL. You can get a start by reviewing the shader code in all of the existing filters within the framework, which show how to achieve all of the effects here in these shaders. Sometimes, combining filters can be as easy as chaining processing operations within a single shader.