From 7cbde4e5a3d83a7ce9178badd452ee6133f97afa Mon Sep 17 00:00:00 2001 From: IOSDEVOPS2201 Date: Wed, 3 Apr 2024 23:18:02 +0300 Subject: [PATCH 1/2] fix of crash --- Source/RSCodeReaderViewController.swift | 12 ++++++++++-- Source/RSCornersLayer.swift | 8 +------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Source/RSCodeReaderViewController.swift b/Source/RSCodeReaderViewController.swift index 070fcf6..3fdea34 100755 --- a/Source/RSCodeReaderViewController.swift +++ b/Source/RSCodeReaderViewController.swift @@ -257,7 +257,11 @@ open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutput if let ticker = self.ticker { ticker.invalidate() } - self.cornersLayer.cornersArray = [] + DispatchQueue.main.async { [weak self] in + guard let self else { return } + self.cornersLayer.setNeedsDisplay() + self.cornersLayer.cornersArray = [] + } } @objc func onTap(_ gesture: UITapGestureRecognizer) { @@ -408,7 +412,11 @@ open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutput } } - self.cornersLayer.cornersArray = cornersArray + DispatchQueue.main.async { [weak self] in + guard let self else { return } + self.cornersLayer.setNeedsDisplay() + self.cornersLayer.cornersArray = cornersArray + } if barcodeObjects.count > 0 { if let barcodesHandler = self.barcodesHandler { diff --git a/Source/RSCornersLayer.swift b/Source/RSCornersLayer.swift index 0600346..9e9da09 100755 --- a/Source/RSCornersLayer.swift +++ b/Source/RSCornersLayer.swift @@ -13,13 +13,7 @@ open class RSCornersLayer: CALayer { @objc open var strokeColor = UIColor.green.cgColor @objc open var strokeWidth: CGFloat = 2 @objc open var drawingCornersArray: Array> = [] - @objc open var cornersArray: Array<[Any]> = [] { - willSet { - DispatchQueue.main.async(execute: { - self.setNeedsDisplay() - }) - } - } + @objc open var cornersArray: Array<[Any]> = [] override open func draw(in ctx: CGContext) { guard let cornerPointsArray = cornersArray as? [[CGPoint]] else { return } From e87854d5ac1e9b302b83597ae41186e578992b5d Mon Sep 17 00:00:00 2001 From: IOSDEVOPS2201 Date: Thu, 4 Apr 2024 11:50:16 +0300 Subject: [PATCH 2/2] fix of crash setNeedsDisplay --- Source/RSCodeReaderViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/RSCodeReaderViewController.swift b/Source/RSCodeReaderViewController.swift index 3fdea34..1fa53dd 100755 --- a/Source/RSCodeReaderViewController.swift +++ b/Source/RSCodeReaderViewController.swift @@ -259,8 +259,8 @@ open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutput } DispatchQueue.main.async { [weak self] in guard let self else { return } - self.cornersLayer.setNeedsDisplay() self.cornersLayer.cornersArray = [] + self.cornersLayer.setNeedsDisplay() } } @@ -414,8 +414,8 @@ open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutput DispatchQueue.main.async { [weak self] in guard let self else { return } - self.cornersLayer.setNeedsDisplay() self.cornersLayer.cornersArray = cornersArray + self.cornersLayer.setNeedsDisplay() } if barcodeObjects.count > 0 {