Skip to content

Commit ca9922c

Browse files
authored
Merge pull request #90 from SDWebImage/bugfix_animatedImage_rare_crash
Fix the issue when dealloc AnimatedImage's native View, the window does not exist and cause internel Crash
2 parents e8dcfc5 + c0f2531 commit ca9922c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ public struct AnimatedImage : PlatformViewRepresentable {
218218
// This is a hack because of Xcode 11.3 bug, the @Published does not trigger another `updateUIView` call
219219
// Here I have to use UIKit/AppKit API to triger the same effect (the window change implicitly cause re-render)
220220
if let hostingView = AnimatedImage.findHostingView(from: view) {
221-
#if os(macOS)
222-
hostingView.viewDidMoveToWindow()
223-
#else
224-
hostingView.didMoveToWindow()
225-
#endif
221+
if let _ = hostingView.window {
222+
#if os(macOS)
223+
hostingView.viewDidMoveToWindow()
224+
#else
225+
hostingView.didMoveToWindow()
226+
#endif
227+
}
226228
}
227229
self.imageLoading.image = image
228230
self.imageLoading.isLoading = false

0 commit comments

Comments
 (0)