I’m working on a WebXR AR project that loads a bunch of GLTF furniture models into a room. All of these models are utilizing KTX textures with a combination of ETC1S and UASTC (for normal maps).
KTX, along with DRACO geometry compression, has worked really well to decrease the GLTF file sizes. I typically see a 60-80% reduction in file size.
However, once I started trying to load a bunch of these GLTF files with KTX textures together, it will often fail during the KTX decode process with the following error printed to the console:
BJS - [17:26:21]: Failed to load KTX2 texture data: Error: KTX2 container - could not transcode the data. TypeError: Cannot convert "undefined" to unsigned long TypeError: Cannot convert "undefined" to unsigned long at Object.toWireType (https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.js:9:49255) at __emval_as (https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.js:9:54139) at <anonymous>:wasm-function:0x255a5 at <anonymous>:wasm-function:0x24ff0 at BasisLzEtc1sImageTranscoder$decodeTables [as decodeTables] (eval at new_ (https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.js:9:34844), <anonymous>:9:10) at https://preview.babylonjs.com/babylon.ktx2Decoder.js:1:16817 at async Promise.all (index 7)
This error occurs after it has already successfully loaded a few GLTF models with KTX textures.
I’m not sure exactly what is going on, my instinct says some kind of memory overflow with the decoder(s) if its failing after successfully decoding so many textures from the GLTF files.
It’s also worth noting that all the models load just fine in isolation. Every single GLTF model loads perfectly in the Babylon Sandbox. It is only when trying to load them in succession that this error occurs.
I have tried throwing in an artificial wait time after each model loads to see if that would work around any kind of memory garbage collection issue but it still occurs even with the artificial wait time.
The frustrating part is that this decode error does not occur consistently. In fact it usually occurs 50-70% of the time. The rest of the time, all the models will load in successfully. Even more frustrating is that it appears to occur only 10-20% of the time when the browser tab is being actively inspected by the Chrome DevTools, it occurs most frequently with the device unhooked from USB and DevTools.
This KTX decode error occurs on both my testing Android devices, both fully up-to-date:
- Google Pixel 4a 5G
- Samsung Galaxy Note 9
I have so far been unable to replicate this decoding error on Desktop. The scene always loads in on Desktop without issue.
Im currently using Babylon 5.0.0 alpha 29