GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Crashes because renderTarget is NULL

Open JensDee opened this issue 12 years ago • 6 comments

I am using GPUImage in an AppStore Application. I am using the version with commit hash 25ce900 (June 9th). Before I was using an old version of GPUImage. Now I am using the new version with the new Framebuffer handling. In our testing phase it looked good.

But obviously it's more unstable as the old version. I get a lot of crashes in GPUImage now.

They almost all have to do with renderTarget in GPUImageFramebuffer being NULL.

Here is the stack trace:

Exception Type: SIGSEGV Exception Codes: SEGV_ACCERR at 0x5

0 CoreFoundation 0x2ed9847e CFGetTypeID + 6 1 CoreVideo 0x2f5b7119 _getCVPixelBuffer + 14 2 CoreVideo 0x2f5b71e1 CVPixelBufferGetBytesPerRow + 6 3 ProCamera 0x00136bdd __56-[GPUImageFramebuffer newCGImageFromFramebufferContents]_block_invoke + 130 4 libdispatch.dylib 0x39aebd3f _dispatch_client_callout + 20 5 libdispatch.dylib 0x39af056f _dispatch_barrier_sync_f_slow + 228 6 ProCamera 0x0010de89 runSynchronouslyOnVideoProcessingQueue + 58 7 ProCamera 0x00136afb -[GPUImageFramebuffer newCGImageFromFramebufferContents] + 576 8 ProCamera 0x00106da3 -[GPUImageFilter newCGImageFromCurrentlyProcessedOutput] + 124 9 ProCamera 0x0010ea91 -[GPUImageOutput imageFromCurrentFramebufferWithOrientation:] + 22 10 ProCamera 0x0011b925 -[GPUImageFilterPipeline currentFilteredFrameWithOrientation:] + 62 11 ProCamera 0x000f8dbd -CCImageProcessOperation process 12 ProCamera 0x000f852f -CCImageProcessOperation start 13 Foundation 0x2f840745 __NSOQSchedule_f + 58 14 libdispatch.dylib 0x39af0cbd _dispatch_queue_drain + 486 15 libdispatch.dylib 0x39aedc6f _dispatch_queue_invoke + 40 16 libdispatch.dylib 0x39af15f1 _dispatch_root_queue_drain + 74 17 libdispatch.dylib 0x39af18dd _dispatch_worker_thread2 + 54 18 libsystem_pthread.dylib 0x39c1cc17 _pthread_wqthread + 296 19 libsystem_pthread.dylib 0x39c1cadc start_wqthread + 6

Any ideas how to fix that? I am not sure if it is relevant, but I am using GPUImagePipeline in an NSOperation. Again, the old version of GPUImage worked totally fine (also GPUImagePipeline in an NSOperation).

This issue relates to #1639

JensDee avatar Jul 23 '14 11:07 JensDee

I have analyzed the issue and I might have found a clue.

The implementation of addFramebufferToActiveImageCaptureList: in GPUImageFramebufferCache seems odd. The frame buffer is retained asynchronously. Why is that? The only call to this method is in newCGImageFromFramebufferContents (GPUImageFramebuffer). The message is sent from within the block runSynchronouslyOnVideoProcessingQueue.

Shouldn't the framebuffer be retained synchronously? I have changed the implementation to the following:

  • (void)addFramebufferToActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; { runSynchronouslyOnVideoProcessingQueue(^{ [activeImageCaptureList addObject:framebuffer]; }); }
  • (void)removeFramebufferFromActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; { runSynchronouslyOnVideoProcessingQueue(^{ [activeImageCaptureList removeObject:framebuffer]; }); }

I have to do intensive testing, but I haven't seen the crash anymore.

Brad, please give me some feedback if my observation and thoughts make sense.

JensDee avatar Jul 23 '14 11:07 JensDee

My last comment was probably bogus although I haven't understood why it's retained asynchronously. Testing showed that the crashes persist. Statistically it crashes most often on iPhone 5.

I guess the following observation might not be leading to a solution, but it might be an interesting clue.

I've set some breakpoints to see what's going on.

 - (CGImageRef)newCGImageFromFramebufferContents;
 {
    if (!renderTarget) {
    return NULL; // breakpoint
 }
 if (renderTarget == (void *)0x00000005) {
   return NULL; // breakpoint
 }
  runSynchronouslyOnVideoProcessingQueue(^{

  if (!renderTarget) {
    // breakpoint
  }
  if (renderTarget == (void *)0x00000005) {
    // breakpoint
  }

  })

Interestingly the renderTarget is sometimes NULL and sometimes 0x00000005. Also renderTarget is often when entering the method, but NULL or 0x00000005 when entering the videoProcessingQueue.

I have no idea if my issue is located somewhere completely different, but I just wanted to point that out. Seems odd.

JensDee avatar Jul 23 '14 14:07 JensDee

@JensDee Based on your comments, seems like you have the way to reproduce the issue. Would you mind sharing this with me. We're also trying to find the cause of the issue. Also, it looks like this is issue is related to #1472, if not the same one.

uros-gardasevic avatar Jul 24 '14 11:07 uros-gardasevic

I am seeing this issue in our crash reports as well.

@BradLarson I have seen several issues are related to this same crash. Any plan on addressing it or is the one workaround the only option.

joshuafeldman avatar Jul 30 '14 00:07 joshuafeldman

@JensDee I am also interested in reproducing this as it is effected a substantial amount of users. Thanks. Please let us know if you have steps to reproduce this

joshuafeldman avatar Aug 09 '14 01:08 joshuafeldman

I got this reports too. It seems when the data send to the queue, usingNextFrameForImageCapture is set to NO at the same time.So I try to change the value of usingNextFrameForImageCapture after the queue is finished.And it works fine up to now. Here is my patch

--- a/framework/Source/GPUImageFilter.m
+++ b/framework/Source/GPUImageFilter.m
@@ -189,11 +189,13 @@ NSString *const kGPUImagePassthroughFragmentShaderString =
         return NULL;
     }

+    // All image output is now managed by the framebuffer itself
+    CGImageRef imageRef = [[self framebufferForOutput] newCGImageFromFramebuffe
+    
     usingNextFrameForImageCapture = NO;
     dispatch_semaphore_signal(imageCaptureSemaphore);

-    // All image output is now managed by the framebuffer itself
-    return [[self framebufferForOutput] newCGImageFromFramebufferContents];
+    return imageRef;
 }

victor-cmcm avatar Aug 19 '14 03:08 victor-cmcm