shamsdev / davinci

An esay-to-use image downloading and caching library for Unity
MIT License
285 stars 52 forks source link

The plugin won't initiate download if the downloading has been intiated once #19

Open bhavin2707 opened 3 years ago

bhavin2707 commented 3 years ago

Hi, so I was developing a puzzle game that uses this plugin as it's a perfect fit. I am downloading the images from google drive at runtime. In the many, I have a script to download the levels sequentially in the background, but the problem occurs when I change the scene, and when I come back, the plugin just won't download the levels. it gets stuck where it was left off. This breaks the flow of downloading the levels and to continue, have to restart the app.

Any suggestions on how to fix it?

ReneB commented 1 year ago

FWIW, I think I've locally fixed this by adding an OnDestroy() method to the Davinci.cs file, like this:

    private void OnDestroy()
    {
        if (underProcessDavincies.ContainsKey(uniqueHash) && underProcessDavincies[uniqueHash] == this) {
            if (enableLog)
                Debug.Log("[Davinci] Removing Davinci object while download unfinished: " + uniqueHash);

            underProcessDavincies.Remove(uniqueHash);
        }
    }

I have not yet been able to test this outside of our own use case, where it seems to fix an issue similar to that of @bhavin2707, but I think I understand the code well enough to determine that the code above makes sure that the Davinci instance being destroyed is the one that any other possible Davinci instances that were waiting for the same file have set their hopes on for getting the file, so if this one is being Destroy()ed, no other Davinci instance should be registered for this specific uniqueHash anymore.