SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.14k stars 219 forks source link

App freezes when imageURL fails caused by infinite loop #200

Closed alanscarpa closed 1 year ago

alanscarpa commented 2 years ago

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?

dreampiggy commented 2 years ago

Please attach the stack trace when your App freeze. Or any demo ?

CWftw commented 2 years ago

We also see this behaviour. This is a very scary bug.

jordaneckhardt commented 2 years ago

I'm experiencing this too. The app freezes and its memory usages grows forever:

memory

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.

dreampiggy commented 2 years ago

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. :(

jordaneckhardt commented 1 year ago

I retested in SDWebImageSwiftUI version 2.2.1 and the issue appears to be fixed.