SDWebImageSwiftUI
SDWebImageSwiftUI copied to clipboard
App freezes when imageURL fails caused by infinite loop
Xcode 13 iOS 14+
When my model retrieves its image URL, the following code is called:
if let imageURL = model.profilePhotoURL, !imageURL.absoluteString.isEmpty {
AnimatedImage(url: imageURL).onFailure(perform: { error in
print("we got an error")
})
Turns out my imageURL was a little misinformed, so loading the image fails.
The issue is that the app freezes on failure. And when I print "we got an error" I can see that we are stuck in an infinite loop, as it gets called over and over. This is causing the app to freeze.
Is there a resolution?
Please attach the stack trace when your App freeze. Or any demo ?
We also see this behaviour. This is a very scary bug.
I'm experiencing this too. The app freezes and its memory usages grows forever:
This issue seems to happen when loading unreachable URLs in your library. For example, this SwiftUI code causes the issue:
@ViewBuilder var profileImage: some View {
AnimatedImage(url: URL(string: "https://avatars.blue.ravetel.com/test.jpeg")!)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: 200, maxHeight: 200, alignment: .center)
.clipShape(Circle())
}
SDWebImage is a really great help for my app. My team and I really appreciate your work.
That said, this is a very serious issue: apps should not freeze when their network requests fail.
An urgent fix would be very much appreciated.
Hi. This SDWebImageSwiftUI seems lag of long-time maintainess. Any contributor can help with ?
To fix this, I guess we should replace all the usage of @State
which binding a class, to use the @StateObject
. (example: ImageManager
is class, so should change it into @StateObject
)
Which bump the min deployment target to iOS 14+
I recently not focus on mobile iOS UI-related development and works on Swift compiler stack related stuff. So maybe I can not manitain too many SDWebImage related project as previous. :(
I retested in SDWebImageSwiftUI version 2.2.1 and the issue appears to be fixed.