prepareForImage causing crash
(this was also reported in the ALAssetsLibrary issue #79, but was probably unrelated and lost in the noise, so filing here)
After pulling latest bits I'm also getting a crash that appears to be related to prepareForImageCapture
I'm using -[GPUImageFilter imageByFilteringImage:] and started getting a crash during the filter dealloc, which happens in destroyFilterFBO:
CFRelease(renderTexture);
If I comment out this line in imageByFilteringImage:
//[self prepareForImageCapture];
then the crash goes away.
I just applied the fix for #79, but I'm still getting crashes and corrupt images unless I comment out that line.
My has a photo-editing component, and when they select "filter" I create a thumbnail of the image, then run through the filters to create a menu with buttons on it populated from [filter imageByFilterImage:thumbnail].
Those thumbnails look fine without prepareForImageCapture, but if I leave that line in, some of them get corrupt, and it feels somewhat random. It almost feels like the filtered thumbnail image is getting created while the filter is still running, if that makes sense.
Sometime the result is noise (like snow on old TVs), sometimes it is partially finished image, sometimes it is just black.
It is also crashing, the last crash I got was here:
void dataProviderUnlockCallback (void *info, const void *data, size_t size) { CVPixelBufferUnlockBaseAddress((CVPixelBufferRef)info, 0); CFRelease((CVPixelBufferRef)info); <------------------------------------------ EXC_BAD_ACCESS }
this is happening on my phone and the simulator.
I've tried various conditions, but I can't reproduce the crash on the renderTexture during the FBO deletion that you're experiencing. What device and iOS version did this happen on? What did you do before deleting the FBO? Did you capture a photo using the asynchronous callback?
Also, note that the texture caches do not work properly in the iOS Simulator, so I don't recommend even trying to run the framework with those enabled there. In fact, I don't do any testing at all using the Simulator, because it's all but useless for photo and video filtering.
If I understand you correctly on the filtering thumbnail process, you take a photo and create a new, smaller UIImage from that. You then have a series of filters that you've set up ahead of time, and for each of these filters you use -imageByFilteringImage: with this small UIImage thumbnail as input. For each filter, you've set prepareForImageCapture. You're then seeing image corruption in the resulting UIImages.
First, you should be safe in not using the fast texture cache support (the prepareForImageCapture) setting with the thumbnails, because the small images should process fast enough that your primary source of overhead should be due to the path to and from UIImage. Second, you should be able to do this more efficiently by creating a GPUImagePicture instance from your thumbnail UIImage, adding all of the different filters as targets of this one image, calling processImage once on it, and then reading back the image from each filter in turn using -imageFromCurrentlyProcessedOutput.
It sounds like there's some bleed over in the texture caches used for the thumbnails, because you're not using an asynchronous callback for the photos like others have. The rendering should come to completion for each of these filters before the image is captured, so the various texture caches may be interfering with one another. I'll see if I can create a centralized cache that all images draw from and see if that would clean this up.
thanks.
Yes I'm using simulator (there is a take picture or select existing photo path in the app I can use to test) but also having same issues on my device.
Simulator is very useful for quick turn arounds while writing the filter selector UI and testing. I already have a custom camera controller as well, so not using any of that code path (though next on my list is modify that to get live filtered view). Would be nice if the texture cache could be disabled while running on simulator (#ifdef TARGET_IPHONE_SIMULATOR...) since the filters themselves are working great.
I wasn't explicitly calling prepareForImageCapture, just using -imageByFilteringImage: which internally is now calling prepareForImageCapture, so I had to comment out that code in GPUImageFilter.
I think your understanding is correct. I'm basically doing something very simple:
UIImage *someImageFromMyCameraOrImagePickerPhotoAlbum; UIImage *thumbnail = [standard code for creating a thumbnail from an existing image]
foreach filter I'm showing in the filter selector UI:
GPUImageOutput
My project is non-ARC (fairly large and haven't had time to convert), and I'm embedding GPUImage as sub-project as described in the README, and that all seems to be working fine.
I've run through the profiler and don't see any leaks, zombies, etc. so it looks like ARC/non-ARC configuration is working ok AFAIKT.
These issues don't look like they ARC-related since they feel more like a CG/CF release/retain issue, but I thought I'd bring it up just in case.
I tried removing the autorelease and just releasing it immediately after I'm done with it and it still has issues.
I'll keep poking around and maybe try repro-ing it in a small sample program.
thanks.