From f6a8f93a7793082478d77561ded1655f35775124 Mon Sep 17 00:00:00 2001 From: Kira <1027610607@qq.com> Date: Tue, 28 Feb 2017 17:14:52 +0800 Subject: [PATCH 1/2] avoid crash --- Regift/Regift.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Regift/Regift.swift b/Regift/Regift.swift index 52cd8d1..3dc58f6 100644 --- a/Regift/Regift.swift +++ b/Regift/Regift.swift @@ -297,6 +297,11 @@ public struct Regift { gifGroup.enter() generator.generateCGImagesAsynchronously(forTimes: times, completionHandler: { (requestedTime, image, actualTime, result, error) in + // if not return when error occured and the time is the last time, gifGroup.leave() will get crash + guard !dispatchError else { + return + } + guard let imageRef = image , error == nil else { print("An error occurred: \(error), image is \(image)") dispatchError = true From 70020fec37371389dc999f7f832d0c62da3ea377 Mon Sep 17 00:00:00 2001 From: Kira <1027610607@qq.com> Date: Wed, 1 Mar 2017 18:12:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=9C=89=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E5=B8=A7=E6=B2=A1=E6=9C=89=E5=8F=96=E5=88=B0=E4=B9=9F?= =?UTF-8?q?=E4=B8=8D=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Regift/Regift.swift | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Regift/Regift.swift b/Regift/Regift.swift index 3dc58f6..7c2bf17 100644 --- a/Regift/Regift.swift +++ b/Regift/Regift.swift @@ -293,19 +293,11 @@ public struct Regift { // Create a dispatch group to force synchronous behavior on an asynchronous method. let gifGroup = Group() - var dispatchError: Bool = false gifGroup.enter() generator.generateCGImagesAsynchronously(forTimes: times, completionHandler: { (requestedTime, image, actualTime, result, error) in - // if not return when error occured and the time is the last time, gifGroup.leave() will get crash - guard !dispatchError else { - return - } - guard let imageRef = image , error == nil else { print("An error occurred: \(error), image is \(image)") - dispatchError = true - gifGroup.leave() return } @@ -318,11 +310,6 @@ public struct Regift { // Wait for the asynchronous generator to finish. gifGroup.wait() - - // If there was an error in the generator, throw the error. - if dispatchError { - throw RegiftError.AddFrameToDestination - } CGImageDestinationSetProperties(destination, fileProperties as CFDictionary)