Просмотр исходного кода

Merge pull request #1956 from ufosky-swift/fix/crash-animated-image-view

Fix a crash on AnimatedImageView
Wei Wang 3 лет назад
Родитель
Сommit
02fe295308
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      Sources/Views/AnimatedImageView.swift

+ 10 - 1
Sources/Views/AnimatedImageView.swift

@@ -560,7 +560,16 @@ extension AnimatedImageView {
                 return
             }
 
-            animatedFrames[previousFrameIndex] = animatedFrames[previousFrameIndex]?.placeholderFrame
+            let previousFrame = animatedFrames[previousFrameIndex]
+            animatedFrames[previousFrameIndex] = previousFrame?.placeholderFrame
+            // ensure the image dealloc in main thread
+            defer {
+                if let image = previousFrame?.image {
+                    DispatchQueue.main.async {
+                        _ = image
+                    }
+                }
+            }
 
             preloadIndexes(start: currentFrameIndex).forEach { index in
                 guard let currentAnimatedFrame = animatedFrames[index] else { return }