Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in Async Operation #146

Closed
greese opened this issue Apr 23, 2021 · 4 comments
Closed

Crash in Async Operation #146

greese opened this issue Apr 23, 2021 · 4 comments
Assignees
Labels
bug Something isn't working fixed The issue is fixed and waiting to confirm

Comments

@greese
Copy link

greese commented Apr 23, 2021

I think there's a bug in here in ImageDecoder.swift:

public func createFrameImage(at index: Int, subsamplingLevel: SubsamplingLevel = .default, decodingOptions: DecodingOptions = .default) -> CGImage? {

...
case .asynchronous:
// Don't consider the subsamplingLevel when comparing the image native size with sizeForDrawing.
guard var size = frameSize(at: index) else {
return nil
}

            if let sizeForDrawing = decodingOptions.sizeForDrawing {
                // See which size is smaller: the image native size or the sizeForDrawing.
                if sizeForDrawing.width * sizeForDrawing.height < size.width * size.height {
                    size = sizeForDrawing
                }
            }

            options = imageSourceAsyncOptions(sizeForDrawing: size, subsamplingLevel: subsamplingLevel)
            **image = CGImageSourceCreateThumbnailAtIndex(imageSource, index, options)**

...

I am getting an occasional crash here and it appears to occur when there is reloading images from the cache. If I felt more confident in my Swift, I'd wrap that bolded line in a DispatchQueue.main.async { } block as I think what is happening is that it's trying to update the UI from outside the main queue. Maybe?

In particular, it seems this code is running inside the DiskCache decode queue.
Screen Shot 2021-04-22 at 19 39 27

As with any async bug based on reloading junk from cache, this is a pain to actually make happen. But the most common scenario is when I am navigating from one view to a previously viewed view with a lot of images in it.

@dmytro-anokhin
Copy link
Owner

Hey, thank you for reporting. This looks like thread explosion, what explains why you encounter it when there are many images. Which device/OS version you running?

@dmytro-anokhin dmytro-anokhin self-assigned this Apr 23, 2021
@dmytro-anokhin dmytro-anokhin added the bug Something isn't working label Apr 23, 2021
@greese
Copy link
Author

greese commented Apr 23, 2021

tvOS, both in simulator and on device (Apple 4k for both). It's a free app in the App Store called Sparq Festival Platform if it helps to look at it.

It does load a lot of images. Basically, it's a streaming platform and we have rows of lazyhstacks forming a carousel of content on each page.

@dmytro-anokhin
Copy link
Owner

Hey, version 2.2.5 limits number of concurrent operations with disk cache. This should solve the problem.

@greese
Copy link
Author

greese commented Apr 28, 2021 via email

@dmytro-anokhin dmytro-anokhin added the fixed The issue is fixed and waiting to confirm label May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed The issue is fixed and waiting to confirm
Projects
None yet
Development

No branches or pull requests

2 participants