Issue with loading KTX2 textures on Android / Chrome

Hi everyone,

I have to load a quite large GLB file (7 MB) which only contains KTX2 compressed textures.
It works fine in most browser, but the following error occurs on certain (mostly older) Android devices in Chrome:
Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Data cannot be cloned, out of memory

Fortunately I found a solution here in this thread (thanks @Evgeni_Popov), which suggests me to decrease the amount of workers for the KTX2 loader.

The thing is I don’t want to set the number of workers hardcoded to 1, because it drastically increases the loading times for most of the other devices / browsers, which would work with the default amount of workers anyway.
I could use something like the userAgent to detect certain constellations though, but it feels not very convenient in general to overrule BabylonJSs default algorithm for evaluating the amount of workers for this specific constellation.

// => from BabylonJS source ()
// Use 50% of the available logical processors but capped at 4.
return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);

My question is if someone has experienced similar issues concerning loading KTX2 textures in Android / Chrome and what could be possible solutions, besides explicitly setting the BABYLON.KhronosTextureContainer2.DefaultNumWorkers variable to 1.

I didn’t append the GLB file to this thread in the first place because it contains potentially confidential data from a certain customer. If it’s required for the analysis I can clarify if I may upload it here into the forum.

Best regards and thanks for your support!

1 Like

Hi TheHOF,

Spoke with our glTF and KTX2 expert @bghgary about this enough to learn that this is perhaps a more complicated scenario than I think I can add much to. He may have some suggested alternatives at some point down the line, but unfortunately if we don’t have a way to dynamically measure when to scale back parallelism (my estimating usable memory, etc.) the only straightforward option that comes to mind is to do it upfront, which as you say will harm the high-performing scenarios and sort of put all required platforms on a level playing field.


There is Navigator.deviceMemory - Web APIs | MDN but support for it is not in all browsers :confused: