Inputs are not always deleted when switching from front to back camera
Aximem opened this issue · comments
Hi,
I have an issue returning the famous :
Multiple audio/video AVCaptureInputs are not currently supported
The issue is in the method when I switch to front / back many times, reinit the camera, reswitch etc.:
fileprivate func updateCameraDevice( deviceType: CameraDevice)
I replaced :
for input in inputs {
if let deviceInput = input as? AVCaptureDeviceInput {
if deviceInput.device == backCameraDevice && cameraDevice == .front {
validCaptureSession.removeInput(deviceInput)
break;
} else if deviceInput.device == frontCameraDevice && cameraDevice == .back {
validCaptureSession.removeInput(deviceInput)
break;
}
}
}
by :
for input in inputs {
if let deviceInput = input as? AVCaptureDeviceInput {
validCaptureSession.removeInput(deviceInput)
}
}
And It works now, I do not have the issue anymore.
It seems that sometimes it doesn't pass in the "if" and "else if" and do not remove anything, then I add a second input and it crash.
I know my solution is not good but it prevents the crash for now.
Does anyone encounter this issue ?
Hi,
My users had the same issue, but I can't reproduce it ...
fixed in v3.1.4 👍
HI! this issue has reappeared, in version 5.1.3 :
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x1b952ea48 __exceptionPreprocess
1 libobjc.A.dylib 0x1b9255fa4 objc_exception_throw
2 AVFoundation 0x1c360bb00 -[AVCaptureSession addInput:]
3 CameraManager 0x104bc2fb4 CameraManager.setupOutputMode(:oldCameraOutputMode:) + 1613 (CameraManager.swift:1613)
4 CameraManager 0x104bd04a4 partial apply for closure #1 in CameraManager.setupCamera(:) + 1634 (CameraManager.swift:1634)
5 CameraManager 0x104bbc65c thunk for @escaping @callee_guaranteed () -> () ()
6 libdispatch.dylib 0x1b91fa610 _dispatch_call_block_and_release
7 libdispatch.dylib 0x1b91fb184 _dispatch_client_callout
8 libdispatch.dylib 0x1b91a7404 _dispatch_lane_serial_drain$VARIANT$mp
9 libdispatch.dylib 0x1b91a7df8 _dispatch_lane_invoke$VARIANT$mp
10 libdispatch.dylib 0x1b91b1314 _dispatch_workloop_worker_thread
11 libsystem_pthread.dylib 0x1b924ab88 _pthread_wqthread
12 libsystem_pthread.dylib 0x1b924d760 start_wqthread