From ad067f7b4e217f27720624b60f495d03891876e0 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 22 Feb 2021 19:45:16 +0800 Subject: [PATCH] Protect when animatedImage does not have CGImage (not possible in real situation) --- SDWebImageSwiftUI/Classes/ImagePlayer.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/ImagePlayer.swift b/SDWebImageSwiftUI/Classes/ImagePlayer.swift index 33454b2..0b9cd02 100644 --- a/SDWebImageSwiftUI/Classes/ImagePlayer.swift +++ b/SDWebImageSwiftUI/Classes/ImagePlayer.swift @@ -78,8 +78,12 @@ public final class ImagePlayer : ObservableObject { self.player = imagePlayer - let posterFrame = PlatformImage(cgImage: animatedImage.cgImage!, scale: animatedImage.scale, orientation: .up) - currentFrame = posterFrame + // Setup poster frame + if let cgImage = animatedImage.cgImage { + currentFrame = PlatformImage(cgImage: cgImage, scale: animatedImage.scale, orientation: .up) + } else { + currentFrame = .empty + } } } }