atteneder / KtxUnity

Load KTX and Basis Universal textures at runtime
Apache License 2.0
218 stars 42 forks source link

Transcoding Basis Files Sometimes Fails #31

Closed badaminatasha closed 3 years ago

badaminatasha commented 3 years ago

Hi!

I have a scene in which I'm trying to download basis textures from urls and apply them to image components in the scene. I've been experiencing problems very similar to the ones indicated in #19, where I have confirmed that the basis texture is properly downloaded with the correct data, but the transcoding fails nonetheless. I'm building for WebGL, and I often find that none of the basis textures load successfully.

I've experimented with a few things that also make me think the issue might be related to CPU load or memory allocation (as in #19 ). I created three WebGL builds that each do something slightly different with respect to texture loading. If you open the developer console you'll be able to see all of the logging for the texture loading, including when an attempt to load begins, when it succeeds, and the actual data in the downloaded basis texture.

Build 1: This is the "control". We attempt to load each texture just once. Textures almost always fail to load in this build. Example: image

Build 2: In this build, if a texture fails to load, we keep trying until it succeeds. This one still has a ton of failures but the image textures are rarely left empty; however, sometimes the incorrect texture is loaded in, even though the logging says that the correct texture was loaded in (possibly a memory allocation issue?). This error is a little difficult to recreate so I have a few examples of what it looks like.

Build 3: This was the most successful build. The texture download requests are queued and so only one can happen at a time. I think this reinforces that it might be a memory allocation or CPU load issue.

Other Stats

I would appreciate any insight you can offer on this issue. Thank you!

atteneder commented 3 years ago

Thanks for this great, very detailed report. Sorry for not answering sooner.

The demo project contains a benchmark scene that loads batches of files. 50 at a time does not produce any errors here (Firefox 84 macOS; Unity 2019.4 LTS).

Which browser are you using?

Can you provide a simple script that reproduces the errors?

Just to clarify: you don't re-use the BasisUniversalTexture objects, right?

Thanks!

badaminatasha commented 3 years ago

I'm using Chrome and we are not reusing the BasisUniversalTexture objects. Actually, we're currently loading the textures from bytes but I noticed you made some updates recently and I was hoping to try loading from URL with your most recent updates (the latest version doesn't require a monobehavior to load from URL, but the version we're using does); however, I don't think the installer package is installing the correct version of KTXUnity. It's still installing 0.9.1, which is from November 2020. Would it be possible to make the latest version of the package available?

atteneder commented 3 years ago

...however, I don't think the installer package is installing the correct version of KTXUnity. It's still installing 0.9.1, which is from November 2020. Would it be possible to make the latest version of the package available?

As you've figured out yourself, the latest changes are in the main branch, but not in a release thus far. After some more tests I'll release, but use the latest change via GIT URL for now.

atteneder commented 3 years ago

You can test KtxUnity 1.0.0-preview now (make sure to enable show preview packages in the package mangager settings).

Let me know how it goes.

badaminatasha commented 3 years ago

Thanks for creating the preview package!

It's been working perfectly: originally, we were downloading the .basis files from S3 and then loading them from bytes, but that was frequently failing. Now, we're loading all of the .basis files directly from URL, and they're all working on the first try, and using LoadFromBytes to load them from cache is working as well :)

atteneder commented 3 years ago

Oh yeah, great to hear!