# Failed to load KTX2 texture data: Error: KTX2 container - could not transcode the data. TypeError: Cannot convert "undefined" to unsigned int

**URL:** <https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726>\
**Category:** Bugs\
**Tags:** texture, ktx2\
**Created:** [March 3, 2023, 9:15pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726 "2023-03-03T21:15:56Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 3, 2023, 9:15pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/1 "2023-03-03T21:15:56Z")

</div>

Hi, we are getting an error with our textures that we converted to KTX2.

See warnings in playground here: [https://playground.babylonjs.com/#20OAV9#10002](https://playground.babylonjs.com/#20OAV9#10002).

We are converting the KTX2 files using the khronos provided converters. Our python code looks like:

```auto
# Convert to KTX2
        tempName = os.path.splitext(filePath)[0] + '-uncompressed.ktx2'
        procresult = subprocess.run(['toktx',
                                      '--t2',
                                      tempName,
                                      filePath],
                                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        checkProcType(procresult, "Error converting texture (KTX2) (OUT: " + tempName + ") : (IN: " + filePath + ")")

        newName = os.path.splitext(filePath)[0] + '.ktx2'
        # Supercompress KTX2
        procresult = subprocess.run(['ktxsc',
                                      '-zcmp',
                                      '-o',
                                      newName,
                                      tempName],
                                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)

```

Any ideas on what may be happening or what that error is telling us?

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 3, 2023, 9:19pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/2 "2023-03-03T21:19:09Z")

</div>

We even used the ktx2 checker provided by khronos and it reports it as a valid ktx2 file.

Side note, we’re 90% certain this worked several weeks ago, so no sure if anything has changed with the transcoder in the last few weeks.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 3, 2023, 9:19pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/3 "2023-03-03T21:19:39Z")

</div>

@bghgary @Evgeni_Popov any ideas what could it be ?

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [March 4, 2023, 12:32pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/4 "2023-03-04T12:32:37Z")

</div>

Sorry to hijack your topic, but i was looking into a way to make ktx2 conversion part of the Blender exporter. All i had seen was C based code.

While i had previously made a DLL for Blender to directly connect a Kinect 2 motion capture device, that seems inferior to a Python based system. Where did you get it?

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 4, 2023, 2:30pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/5 "2023-03-04T14:30:45Z")

</div>

Just something we wrote. Not a blender plugin or anything, part of a larger texture conversion system that takes in pngs and spits out a variety of image formats in different LODs.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 4, 2023, 3:38pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/6 "2023-03-04T15:38:20Z")

</div>



---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 4, 2023, 3:40pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/7 "2023-03-04T15:40:45Z")

</div>

We don’t support R8G8B8 SRGB in the KTX2 decoder, try R8G8B8A8 SRGB instead.

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 4, 2023, 6:38pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/8 "2023-03-04T18:38:06Z")

</div>

Will give that a try monday and report back! Thank you! Is any of the ktx2 requirements for babylonjs documented anywhere?

---

<div class="post-metadata">

**Author:** ![RPaladin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rpaladin/32/27367_2.png) [@RPaladin](https://forum.babylonjs.com/u/RPaladin)\
**Post date:** [March 4, 2023, 8:08pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/9 "2023-03-04T20:08:36Z")

</div>

Here are all of the supported KTX2 decoder types for Babylon.js:

> <https://github.com/BabylonJS/Babylon.js/tree/master/packages/tools/ktx2Decoder/src/Transcoders>
>
> //github.com/BabylonJS/Babylon.js/tree/master/packages/tools/ktx2Decoder/src/Transcoders

Here is also a list of supported formats for KTX texture containers for WebGL:

> **[Multi-Platform Compressed Textures | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/mutliPlatTextures#khronos-texture-container-format-ktx-files)**
>
> Learn all about multi-platform compressed textures in Babylon.js.

* * *

Unrelated, for those unsure what the differences are between KTX and KTX2, here’s a good summary:

> [@KTX vs KTX2 format](https://forum.babylonjs.com/t/ktx-vs-ktx2-format/37502/2):
>
> KTX2(and .basis) have this “Universal supercompression” Meaning that once downloaded, a worker thread transcodes them to a real compression format. Meaning it picks the optimal format for the hardware the person is viewing with and that is what’s sent back to main thread The first article is talking about device specific the ‘older’ way. Which is you offline generate a version of a texture for each different CPU (mytex-astc.ktx, mytex-etc2.ktx, mytex-pvrtc.ktx etc etc ). Babylon for instance t…

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 5, 2023, 12:39am UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/10 "2023-03-05T00:39:09Z")

</div>

Still failing, see [https://playground.babylonjs.com/#20OAV9#10015](https://playground.babylonjs.com/#20OAV9#10015) (only the first texture was converted to R8G8B8A8 SRGB ([https://storage.googleapis.com/vcassets/production/vcn/var/000006/0000786f/Texture/1025.ktx2](https://storage.googleapis.com/vcassets/production/vcn/var/000006/0000786f/Texture/1025.ktx2)).

New code to transform is

```auto
toktx --t2 --target_type RGBA test-uncompressed.ktx2 1024.png
ktxsc -zcmp -o 1025.ktx2 test-uncompressed.ktx2

```

Attached the KTX info as well:

```auto
ktxinfo 1025.ktx2
Header

identifier: «KTX 20»\r\n\x1A\n
vkFormat: VK_FORMAT_R8G8B8A8_SRGB
typeSize: 1
pixelWidth: 1024
pixelHeight: 1024
pixelDepth: 0
layerCount: 0
faceCount: 1
levelCount: 1
supercompressionScheme: KTX_SS_ZSTD
dataFormatDescriptor.byteOffset: 0x68
dataFormatDescriptor.byteLength: 92
keyValueData.byteOffset: 0xc4
keyValueData.byteLength: 108
supercompressionGlobalData.byteOffset: 0
supercompressionGlobalData.byteLength: 0

Level Index

Level0.byteOffset: 0x130
Level0.byteLength: 376387
Level0.uncompressedByteLength: 4194304

Data Format Descriptor

DFD total bytes: 92
BDB descriptor type 0x0000 vendor id = 0x00000
Descriptor block size 88 (4 samples) versionNumber = 0x0002
Flags 0x00 Xfer 02 Primaries 01 Model 001
Dimensions: 1,1,1,1
Plane bytes: 0,0,0,0,0,0,0,0
    Sample 0
Qualifiers 0 Channel 0x0 (R) Length 8 bits Offset 0
Position: 0,0,0,0
Lower 0x00000000
Upper 0x000000ff
    Sample 1
Qualifiers 0 Channel 0x1 (G) Length 8 bits Offset 8
Position: 0,0,0,0
Lower 0x00000000
Upper 0x000000ff
    Sample 2
Qualifiers 0 Channel 0x2 (B) Length 8 bits Offset 16
Position: 0,0,0,0
Lower 0x00000000
Upper 0x000000ff
    Sample 3
Qualifiers 1 Channel 0xf (A) Length 8 bits Offset 24
Position: 0,0,0,0
Lower 0x00000000
Upper 0x000000ff

Key/Value Data

KTXorientation: rd
KTXwriter: ktxsc v4.0.0-beta6~6 / libktx v4.0.0~5
KTXwriterScParams: -zcmp

```

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 5, 2023, 8:26pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/11 "2023-03-05T20:26:40Z")

</div>

The current code for the MSC transcoder module needs that `supercompressionGlobalData` have non empty data to work in the `ETC1S` case. I will have to see if we can do something about it.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 6, 2023, 11:23am UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/12 "2023-03-06T11:23:35Z")

</div>

It seems that not specifying an encoding scheme with `ktxsc` will generate a **ETC1S** encoded file. But Zstandard compression (`--zcmp`) is not supported for **ETC1S**. Excerpt from `ktxsc -h`:

```auto
  --zcmp [<compressionLevel>]
               Supercompress the data with Zstandard. Implies --t2. Can be used
               with data in any format except ETC1S / BasisLZ. Most
               effective with RDO-conditioned UASTC or uncompressed formats. The
               optional compressionLevel range is 1 - 22 and the default is 3.
               Lower values=faster but give less compression. Values above 20
               should be used with caution as they require more memory.

```

So, you should either use **UASTC** if you want to compress with Zstandard, or select the **ETC1S** compression scheme:

- ktxsc --encode uastc --zcmp -o 1025.ktx2 test-uncompressed.ktx2
- ktxsc --encode etc1s -o 1025.ktx2 test-uncompressed.ktx2

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 6, 2023, 3:11pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/13 "2023-03-06T15:11:45Z")

</div>

This was it!! Quick question on the compressionLevel. Is “speed” affect the speed of de-compression at runtime? or only the speed of the conversion to initially compress it. Because we dont care about the speed of compression, but we absolutely care about decompression.

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 6, 2023, 3:16pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/14 "2023-03-06T15:16:05Z")

</div>

Also for anyone coming along with same problem, we were able to change back to RGB instead of RGBA and have it still work. Was just the ESTC1S vs UASTC

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 6, 2023, 5:32pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/15 "2023-03-06T17:32:34Z")

</div>

> [@Jon\_Jekeli](#):
>
> This was it!! Quick question on the compressionLevel. Is “speed” affect the speed of de-compression at runtime? or only the speed of the conversion to initially compress it

In my understanding, the compression level affects the speed only at the compression stage.

---

<div class="post-metadata">

**Author:** ![Jon\_Jekeli](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jon_jekeli/32/1697_2.png) [@Jon\_Jekeli](https://forum.babylonjs.com/u/Jon_Jekeli)\
**Post date:** [March 6, 2023, 5:51pm UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/16 "2023-03-06T17:51:21Z")

</div>

> [@Evgeni\_Popov](#):
>
> In my understanding, the compression level affects the speed only at the compression stage.

Thanks!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 8, 2023, 10:08am UTC](https://forum.babylonjs.com/t/failed-to-load-ktx2-texture-data-error-ktx2-container-could-not-transcode-the-data-typeerror-cannot-convert-undefined-to-unsigned-int/38726/17 "2023-03-08T10:08:23Z")

</div>


