enable3d icon indicating copy to clipboard operation
enable3d copied to clipboard

Repeat calls to third.load.<x> crash. (Cache is trying to use cache payload as url)

Open zvodd opened this issue 8 months ago • 5 comments

Describe the bug When loading a GLTF or other files through the three graphics package. The function that queries the cache, supplies the cached binary array to this.gltfLoader.load instead of the url.

e.g.

  public gltf(url: string): Promise<GLTF> { 
    // if the cache has a value this resolves to the payload and key becomes a big byte array
    const key = this.cache.get(url)
    url = key ? key : url

    return new Promise(resolve => {
      this.gltfLoader.load(url, (gltf: GLTF) => {
        resolve(gltf)
      })
    })
  }

This means a second call to load the same file, hits an exception when it gets a byte array instead of a url string.

zvodd avatar Apr 28 '25 05:04 zvodd

Can you please share a code snippet where you get a error? I can't reproduce the error.

What three.js version are you using?

yandeu avatar Apr 29 '25 07:04 yandeu

I am using a slightly dated "three": "0.171.0" ...that could be the issue ... though, looking at the code - I assume cache.get(url) returns the cache payload rather than the url and gltfLoader.load(<some_array>) would fail.

If you care to check out my gamejam game. Hit backslash to open the debug overlay and click "preload scene" https://github.com/zvodd/phaser_3dnoodles/tree/7c5cb6e27d78d2076c6c27a3812c88a9a6457c9f

zvodd avatar Apr 29 '25 07:04 zvodd

Try to use the preloader:

await this.load.preload('flower', '/assets/flower.glb')
const gltf1 = await this.load.gltf('flower')
const gltf2 = await this.load.gltf('flower')

Once preloaded, it will use the browser cache. Unfortunately (and I believe is still the case) it is not possible to cache a gltf model. Every time you reuse the gltf model, it should go through the loader which will do some parsing (or something like this) and will create a unique object each time.

yandeu avatar Apr 29 '25 12:04 yandeu

OK I'll try that, sorry about the pull request. I got abit discombobulated navigating javascript build systems and setting up a private npr (Verdaccio). I never even tried running the test suite before pushing.

zvodd avatar Apr 30 '25 02:04 zvodd

Don't worry. My enable3d documentation is bad and I should use preload in all examples.

yandeu avatar May 01 '25 19:05 yandeu