1

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
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Abhishek B
  • 157
  • 8
  • format your question correctly. – chirag90 Sep 13 '19 at 10:51
  • https://stackoverflow.com/questions/54248552/application-crashing-while-accessing-microphone-in-ios-12-1-2-for-iphone-xs (in some other languages, but logic is the same) ? – Larme Sep 13 '19 at 10:55
  • @Larme what link you have provided is not related to this crash . I also gone through this link . But it didn't fix my issue . – Abhishek B Sep 13 '19 at 11:00
  • What's your code? Only in iPhone X? And in iOS12 it works? In an iPhone 8? iPhone XS? iPad? Could it be limited to the video camera? Cf. logic there https://stackoverflow.com/questions/53213054/crash-when-using-front-camera-only-on-pre-iphone-7-devices/53214766#53214766 – Larme Sep 13 '19 at 11:02
  • Yes in all other devices its works fine , Only getting crash on iPhone XR – Abhishek B Sep 13 '19 at 11:03

2 Answers2

4

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()

  • Thanks @syed with captureSessionInstance.automaticallyConfiguresCaptureDeviceForWideColor = false its working fine . – Abhishek B Sep 16 '19 at 05:35
1

The error message says:

-[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'

You are trying to pass a value that is not available. According to the apple docs not all devices have the same list of available color spaces. https://developer.apple.com/documentation/avfoundation/avcapturedevice/1648668-activecolorspace

This is why it only fails on XR as you mentioned.

You need to check what values are supported on the current device using activeFormat.supportedColorSpaces before you try to set it.

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56