piemonte / PBJVision

📸 iOS Media Capture – features touch-to-record video, slow motion, and photography

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EXC_BAD_ACCESS on didCaptureVideoSampleBuffer delegate method

jinhk86 opened this issue · comments

When I implement the delegate method vision: didCaptureVideoSampleBuffer: to get progress, I'm getting crash in PBJVision.m file where calls this delegate method.

if ([_delegate respondsToSelector:@selector(vision:didCaptureVideoSampleBuffer:)]) {
    [_delegate vision:self didCaptureVideoSampleBuffer:bufferToWrite];
}

If I temporarily change bufferToWrite to nil, I'm not getting crash. What's your thought?

commented

I'm also getting this error. Have you found a solution?

I temporarily changed the bufferToWrite variable to nil since I'm not using sampleBuffer variable in the delegate method.

Same issue here - note I'm using the library in a Swift project

An other way is to remove the delegate response by deleting these lines from your ViewController:

  // progress
  func vision(vision: PBJVision, didCaptureVideoSampleBuffer sampleBuffer: CMSampleBuffer) {
  }
  func vision(vision: PBJVision, didCaptureAudioSample sampleBuffer: CMSampleBuffer) {
  }

or

- (void)vision:(PBJVision *)vision didCaptureVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
  //    NSLog(@"captured audio (%f) seconds", vision.capturedAudioSeconds);
}
- (void)vision:(PBJVision *)vision didCaptureAudioSample:(CMSampleBufferRef)sampleBuffer
{
  //    NSLog(@"captured video (%f) seconds", vision.capturedVideoSeconds);
}

still have this bug using PBJVision in Swift.
any ideas how to fix it, in case I really need video progress? =)

Having the same problem in Swift. Not really sure how to fix this if you need CMSampleBufferRef in your delegate, but in other cases this can be solved either by passing nil to sampleBuffer variable or by creating new delegate method that is not sending sampleBuffer variable at all.
In all cases PBJVision source code has to be modified, unfortunately, until this is fixed.

Problem in the metod captureOutput: didOutputSampleBuffer: fromConnection:

        [self _enqueueBlockOnMainQueue:^{
            if ([_delegate respondsToSelector:@selector(vision:didCaptureVideoSampleBuffer:)]) {
                [_delegate vision:self didCaptureVideoSampleBuffer:bufferToWrite];
            }
        }];

_enqueueBlockOnMainQueue - is asynchronous and bufferToWrite release before didCaptureVideoSampleBuffer func of delegate.
For resolve you can comment async func. Like this.

        //[self _enqueueBlockOnMainQueue:^{
            if ([_delegate respondsToSelector:@selector(vision:didCaptureVideoSampleBuffer:)]) {
                [_delegate vision:self didCaptureVideoSampleBuffer:bufferToWrite];
            }
        //}];

or
CFRetain(sampleBuffer);
[self _enqueueBlockOnMainQueue:^{
if ([_delegate respondsToSelector:@selector(vision:didCaptureVideoSampleBuffer:)]) {
[_delegate vision:self didCaptureVideoSampleBuffer:bufferToWrite];
CFRelease(bufferToWrite);
}
}];

@vixentael @crazyjooe if you're using swift, check out github.com/nextlevel/NextLevel

@eserikov7 thanks for the comments, 0.5.1 has this change, should be resolved by updating your pod, are you seeing otherwise?