Search code examples
iosuikitavfoundation

Application crashing when opening camera to capture video only on iPhone XR


I'm getting the below crash and error message only on iPhone XR.

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'


CoreFoundation                       0x00000002038d23a8 __exceptionPreprocess + 232
1   libobjc.A.dylib                      0x0000000202ad7d00 objc_exception_throw + 56
2   AVFoundation                         0x0000000209950220 __47-[AVCaptureFigVideoDevice setActiveColorSpace:]_block_invoke + 204
3   libdispatch.dylib                    0x00000002032e1884 _dispatch_client_callout + 16
4   libdispatch.dylib                    0x00000002032ee404 _dispatch_lane_barrier_sync_invoke_and_complete + 56
5   AVFoundation                         0x00000002099500e4 -[AVCaptureFigVideoDevice setActiveColorSpace:] + 132
6   Foundation                           0x000000020433247c ___NSSetLongLongValueAndNotify_block_invoke + 44
7   Foundation                           0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
8   Foundation                           0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
9   Foundation                           0x0000000204331860 _NSSetLongLongValueAndNotify + 280
10  AVFoundation                         0x000000020996c808 -[AVCaptureSession _updateDeviceActiveFormatsAndActiveConnections] + 5064
11  AVFoundation                         0x000000020996acac -[AVCaptureSession _buildAndRunGraph] + 104
12  AVFoundation                         0x0000000209964ce4 -[AVCaptureSession _commitConfiguration] + 108
13  Foundation                           0x0000000204332208 ___NSSetObjectValueAndNotify_block_invoke + 44
14  Foundation                           0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
15  Foundation                           0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
16  Foundation                           0x0000000204330b8c _NSSetObjectValueAndNotify + 280
17  CameraUI                             0x00000002207ba3a0 -[CAMModeAndDeviceCommand executeWithContext:] + 668
18  CameraUI                             0x00000002207b9a74 -[CAMCaptureEngine _executeCommand:withContext:] + 212
19  CameraUI                             0x00000002207b9b2c -[CAMCaptureEngine _executeCommand:withContext:] + 396
20  CameraUI                             0x00000002207b9528 __35-[CAMCaptureEngine enqueueCommand:]_block_invoke + 104

Solution

  • If u are trying to run a camera session by configuring AVCaptureSession in your application it automatically adjusts AVCaptureDevice's activeFormat and activeColorSpace properties based on the supportedColorSpaces of the device's formats and the current AVCaptureSession topology. Try setting the property "automaticallyConfiguresCaptureDeviceForWideColor" of class AVCaptureSession to false.

    captureSessionInstance.automaticallyConfiguresCaptureDeviceForWideColor = false

    Also stop the running capture session when your not in that view and restart again when needed.

    captureSessionInstance.stopRunning()

    captureSessionInstance.startRunning()