App is crash [AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration

Greetings everyone,

My app is crash when i open camera screen open and close i have added subview in the camera that shows the main screen but the app does not crash every time, the app works well 5-6 times after the app crashes.

I'm using instead of the Quickpose.ai library and the app crashes instead of lib. so I don't know where is the problem i have shown some code and my crash log.

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'
*** First throw call stack:
(0x1889f4870 0x180d13c00 0x1a4e30b44 0x10505cff0 0x1047ed7cc 0x1047ed84c 0x105824f50 0x105826b34 0x10582e98c 0x10582f728 0x10583c5f8 0x10583bc2c 0x1f2365964 0x1f2365a04)
libc++abi: terminating due to uncaught exception of type NSException
![]("https://developer.apple.com/forums/content/attachment/a1eeece3-6529-4c79-8931-963f58818a93" "title=Screenshot 2023-12-12 at 9.35.27 AM.png;width=1920;height=1080")


![]("https://developer.apple.com/forums/content/attachment/2184c975-e299-40e4-b466-cafa5165ae03" "title=Screenshot 2023-12-12 at 9.35.32 AM.png;width=1920;height=1080")
`
![]("https://developer.apple.com/forums/content/attachment/d78ac3ac-313a-4df9-960d-0c58c3087bec" "title=Screenshot 2023-12-15 at 12.11.38 PM.png;width=1920;height=1080")
``

I'm having the same issue. *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'. It mainly appears on iOS17 devices, and a small number of iOS16 devices. The reason for this is that on both systems, a nomain-thread is used to startRunning the session, as there is a thread warning when the main thread starts. This crashes inside the API method, suspected to be thread call. Did you add the sub try to be the AVCaptureVideoPreviewLayer class? I've fixed this, I would recommend creating the AVCaptureVideoPreviewLayer instance at initialization time in the CameraPreViewController class. Regarding synchronizing access to the capture manager, I would recommend creating a dispatch queue just for this purpose, storing it as a property of the Camera-SessionManager class, then wrapping the calls in startRunning and stopRunning within dispatch sync blocks using this dispatch queue. 1、init session 2、create AVCaptureVideoPreviewLayer 3、setting session input and output 4、session startRunner with custom dispatch_queue_t.

App is crash [AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration
 
 
Q