macOS, AVCapture crash

We found that crashes occur on some specific devices. But don't know the root cause for it. It only appears on the user side and cannot be reproduced on our local devices.

From the stack, a crash occurs inside AVCapture after calling discoverySessionWithDeviceTypes:

NSArray<AVCaptureDevice*>* GetVideoCaptureDevices() {
  NSArray* captureDeviceType = @[
    AVCaptureDeviceTypeBuiltInWideAngleCamera,
    AVCaptureDeviceTypeExternalUnknown
  ];

  AVCaptureDeviceDiscoverySession* deviceDiscoverySession =
      [AVCaptureDeviceDiscoverySession
          discoverySessionWithDeviceTypes:captureDeviceType
                                mediaType:AVMediaTypeVideo
                                 position:AVCaptureDevicePositionUnspecified];
  return deviceDiscoverySession.devices;
}

The following is the crash call stack:

OS Version: macOS 13.5 (22G74)
Report Version: 104

Crashed Thread: 10301

Application Specific Information:
Fatal Error: EXC_BAD_INSTRUCTION / EXC_I386_INVOP / 0x7ff8194b3522

Thread 10301 Crashed:
0   AppKit                          0x7ff8194b3522      -[NSApplication _crashOnException:]
1   AppKit                          0x7ff8194b32b3      -[NSApplication reportException:]
2   AppKit                          0x7ff819569efa      NSApplicationUncaughtExceptionHandler
3   CoreFoundation                  0x7ff8161c010a      <unknown>
4   libobjc.A.dylib                 0x7ff815c597c8      <unknown>
5   libc++abi.dylib                 0x7ff815f926da      std::__terminate
6   libc++abi.dylib                 0x7ff815f92695      std::terminate
7   libobjc.A.dylib                 0x7ff815c65929      <unknown>
8   libdispatch.dylib               0x7ff815e38046      _dispatch_client_callout
9   libdispatch.dylib               0x7ff815e39266      _dispatch_once_callout
10  AVFCapture                      0x7ff8328cafb6      +[AVCaptureDALDevice devices]
11  AVFCapture                      0x7ff832996410      +[AVCaptureDevice_Tundra _devicesWithAllowIOSMacEnvironment:]
12  AVFCapture                      0x7ff83299652b      +[AVCaptureDevice_Tundra _devicesWithDeviceTypes:mediaType:position:allowIOSMacEnvironment:]
13  AVFCapture                      0x7ff83299e8c0      -[AVCaptureDeviceDiscoverySession_Tundra _initWithDeviceTypes:mediaType:position:allowIOSMacEnvironment:prefersUnsuspendedAndAllowsAnyPosition:]
14  AVFCapture                      0x7ff83299e7a4      +[AVCaptureDeviceDiscoverySession_Tundra discoverySessionWithDeviceTypes:mediaType:position:]
15  Electron Framework              0x119453784         media::GetVideoCaptureDevices (video_capture_device_avfoundation_helpers.mm:22)

I want to know what is the root cause of this crash. How should I simulate it and fix it?

Any suggestions would be highly appreciated. Thank you.

macOS, AVCapture crash
 
 
Q