Skip to content

Commit b49a39a

Browse files
committed
Fix occasional crash configuring AVCaptureSession
1 parent 8f4067a commit b49a39a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

wire-ios/Wire-iOS/Sources/UserInterface/Camera/CameraController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ final class CameraController {
4646
init?(camera: SettingsCamera) {
4747
guard !UIDevice.isSimulator else { return nil }
4848
self.currentCamera = camera
49-
setupSession()
5049
self.previewLayer = AVCaptureVideoPreviewLayer(session: session)
50+
51+
// `setupSession()` performs session configuration on a dedicated serial queue. This needs to happen after the
52+
// `previewLayer` is created to avoid simultaneous session configuration across different threads as
53+
// `AVCaptureVideoPreviewLayer` appears to configure the session internally on the main thread during init.
54+
// Configuring the `AVCaptureSession` from multiple threads can lead to a deadlock.
55+
setupSession()
5156
}
5257

5358
// MARK: - Session Management

0 commit comments

Comments
 (0)