Search code examples
macosopenglgpuimage

GPUImageView hanging on presentFrameBuffer when OpenGL Profiler attached


I've submitted an issue on the GPUImage github page, but thought I would see if anyone here has a workaround or a better idea of the cause of the problem.

I have a GPUImageView fed by GPUImageRawDataInput in an OS X application. If I attach OpenGL Profiler and turn tracing on while updating, processing gets stuck in [NSOpenGLContext flushBuffer] (specifically in __psynch_mutexwait). For a simple test case, I just have a view controller with a button and custom view of class GPUImageView and the following code in the controller:

-(void)awakeFromNib{
    [super awakeFromNib];
    NSString *fname = [[NSBundle mainBundle] pathForResource:@"TestImage" ofType:@"dat"];
    NSError *err = nil;
    if(!fname){
        err = [NSError errorWithDomain:@"ViewController" code:0
                              userInfo:@{NSLocalizedFailureReasonErrorKey:@"No selected data file!"}];
    }else{
        _rawDataFromFile = [NSData dataWithContentsOfFile:fname
                                                  options:NSDataReadingMappedIfSafe | NSDataReadingUncached
                                                    error:&err];
    }
    if(err){
        [self presentError:err];
        return;
    }
    [self.imageView setFillMode:kGPUImageFillModePreserveAspectRatio];
    [self.imageView setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:1.0];
    GLubyte* data = (GLubyte *)[self.rawDataFromFile bytes];
    _inputFilter = [[GPUImageRawDataInput alloc] initWithBytes:data
                                                          size:CGSizeMake(1024, 241)
                                                   pixelFormat:GPUPixelFormatLuminance
                                                          type:GPUPixelTypeUByte];
    [self.inputFilter addTarget:self.imageView];
}

- (IBAction)updateAction:(id)sender {
    if (_inputFilter) {
        [self.inputFilter useNextFrameForImageCapture];
        [self.inputFilter processData];
    }
}

Any ideas as to why this might hang only when the profiler is attached? Thanks!

I'm running on a mid 2012 macbook pro, OS X 10.11.4.


Solution

  • I just realized a mistake in my "simple" test case which solves my problem. It points out a potential solution to other problems people might have with GPUImage in OS X apps, so I'm posting it as a solution here.

    If you use Interface Builder to place your GPUImageView inside an NSView, make sure you turn the parent view's Core Animation Layer off unless you explicitly need it and know what you are doing (it is on by default).