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

Bug: DownloadTextureAsync does not returned the cached item if was previously downloaded #39

Open
SimonDarksideJ opened this issue Dec 18, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@SimonDarksideJ
Copy link
Contributor

SimonDarksideJ commented Dec 18, 2023

Reality Collective - Utilities Bug Report

Describe the bug

DownloadTextureAsync does not returned the cached item if was previously downloaded. If the file exists locally, it is not returned.

To Reproduce

  1. Use DownloadTextureAsync to download a texture
  2. Call DownloadTextureAsync a second time to download it again
  3. check downloads

Expected behavior

The cached item should be returned and a web call to download it again should not happen.

Actual behavior

Texture is downloaded again

Additional context

This is where the fault lies

            if (url.Contains("file://"))
            {
                isCached = true;
                cachePath = url;
            }
            else
            {
                isCached = TryGetDownloadCacheItem(fileName, out cachePath, downloadLocation, ForceDownload || downloadTextureArgs.ForceDownload);
            }

            using var webRequest = UnityWebRequestTexture.GetTexture(url); 
            var response = await ProcessRequestAsync(webRequest, downloadTextureArgs); <-- downloads again even though file exists

            if (!response.Successful)
            {
                Debug.LogError(GenerateErrorMessage("texture", url, response));
                return null;
            }

            var downloadHandler = (DownloadHandlerTexture)webRequest.downloadHandler;

This should be used BEFORE the web call

            if (isCached)
            {
                url = cachePath;
            }

TO run the web call to load the file bytes locally

@SimonDarksideJ SimonDarksideJ added the bug Something isn't working label Dec 18, 2023
SimonDarksideJ added a commit that referenced this issue Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant