From a9746bf861e1fbbccf550249830f8517ae187717 Mon Sep 17 00:00:00 2001 From: Jon Andersen Date: Thu, 7 Sep 2017 17:06:21 -0400 Subject: [PATCH] Ensure preview layer is accessed on main thread --- Source/SwiftyCamViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index 7a8cc77..9234bdc 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -503,6 +503,9 @@ open class SwiftyCamViewController: UIViewController { flashView?.alpha = 0.85 previewLayer.addSubview(flashView!) } + + //Must be fetched before on main thread + let previewOrientation = previewLayer.videoPreviewLayer.connection!.videoOrientation sessionQueue.async { [unowned self] in if !movieFileOutput.isRecording { @@ -519,7 +522,7 @@ open class SwiftyCamViewController: UIViewController { movieFileOutputConnection?.isVideoMirrored = true } - movieFileOutputConnection?.videoOrientation = self.orientation.getVideoOrientation() ?? self.previewLayer.videoPreviewLayer.connection!.videoOrientation + movieFileOutputConnection?.videoOrientation = self.orientation.getVideoOrientation() ?? previewOrientation // Start recording to a temporary file. let outputFileName = UUID().uuidString