Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does AVCaptureStillImageOutput jpegStillImageNSDataRepresentation throw an exception with a NULL sample buffer?

Tags:

ios

iphone

NSInvalidArgumentException * +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL sample buffer.

This seems to happen if you take too many (too fast) photos in a row.

like image 248
pbx Avatar asked Dec 09 '11 21:12

pbx


2 Answers

Well it says in the documentation:

This method throws an NSInvalidArgumentException if jpegSampleBuffer is NULL or not in the JPEG format.

So it probably means that the data being expected by the JPEG processor is not in the buffer yet (if you take pictures too quickly).

So either you check your imageSampleBuffer for NULL or what I did: I wrapped the entire thing in an if-statement checking: CMSampleBufferIsValid(imageSampleBuffer) but don't really know if that is the correct way to safeguard this. Documentation is a bit sparse around.

like image 126
Alper Avatar answered Oct 25 '22 00:10

Alper


Like always, check for error.

[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection
                                                   completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     if (!error) {

Also just incase, here's (IBAction)didTakePhoto

if (self.captureSession.isRunning) {
    [self captureNow];
        //Custom capture method.
}
like image 23
benjaminhallock Avatar answered Oct 25 '22 00:10

benjaminhallock