piemonte / PBJVision

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AVCaptureSession can't stopRunning between calls to beginConfiguration / commitConfiguration

tettoffensive opened this issue · comments

Getting this crash from some of our users:

AVCaptureSession can't stopRunning between calls to beginConfiguration / commitConfiguration

Fatal Exception: NSGenericException
0  CoreFoundation                 0x18118ae38 __exceptionPreprocess
1  libobjc.A.dylib                0x1807eff80 objc_exception_throw
2  AVFoundation                   0x1878ca0fc -[AVCaptureSession stopRunning]
3  PBJVision                      0x1011b66a4 __24-[PBJVision stopPreview]_block_invoke (PBJVision.m:1214)
4  libdispatch.dylib              0x180bd54bc _dispatch_call_block_and_release
5  libdispatch.dylib              0x180bd547c _dispatch_client_callout
6  libdispatch.dylib              0x180be14c0 _dispatch_queue_drain
7  libdispatch.dylib              0x180bd8f80 _dispatch_queue_invoke
8  libdispatch.dylib              0x180bd547c _dispatch_client_callout
9  libdispatch.dylib              0x180be3914 _dispatch_root_queue_drain
10 libdispatch.dylib              0x180be30b0 _dispatch_worker_thread3
11 libsystem_pthread.dylib        0x180ded470 _pthread_wqthread
12 libsystem_pthread.dylib        0x180ded020 start_wqthread

This is also a hugely common crash for our app as recorded by crashlytics.

My guess is this is a concurrency issue:
Since most places begin/commit we're on the capture session queue. but not in this block of code in - (void)_sessionStarted:(NSNotification *)notification. Here's what I'm thinking to modify.

AVCaptureDevice *device = [_currentInput device];
 if (device) {
                [self _enqueueBlockOnCaptureSessionQueue:^{
                    [self willChangeValueForKey:@"currentDevice"];
                    [self _setCurrentDevice:device];
                    [self didChangeValueForKey:@"currentDevice"];
                }];
            }

Hey @tettoffensive thanks for the interest in the library and your comments. I haven't been able to work on contributions due to a contract I'm involved with at the moment. If you or others submit a pull request, I can get a collaborator to get it merged in.