BabylonJS/Babylon.js · error · Error

Invalid table entry

Error message

Invalid table entry

What it means

HufBuildDecTable builds the fast lookup table used by Babylon.js's EXR huf decoder. When decompressing a huf-compressed EXR block, if a canonical Huffman code's value does not fit within its bit length (`c >> l !== 0`) the code table is internally inconsistent, so the loader throws "Invalid table entry" instead of producing garbage pixels. It is thrown only while decoding huf-compressed EXR data via HufUncompress.

Source

Thrown at packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts:282

    HufCanonicalCodeTable(hcode);
}

function HufLength(code: number) {
    return code & 63;
}

function HufCode(code: number) {
    return code >> 6;
}

function HufBuildDecTable(hcode: Array<any>, im: number, iM: number, hdecod: Array<any>) {
    for (; im <= iM; im++) {
        const c = HufCode(hcode[im]);
        const l = HufLength(hcode[im]);

        if (c >> l) {
            throw new Error("Invalid table entry");
        }

        if (l > HUF_DECBITS) {
            const pl = hdecod[c >> (l - HUF_DECBITS)];

            if (pl.len) {
                throw new Error("Invalid table entry");
            }

            pl.lit++;

            if (pl.p) {
                const p = pl.p;
                pl.p = new Array(pl.lit);

                for (let i = 0; i < pl.lit - 1; ++i) {
                    pl.p[i] = p[i];
                }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Re-obtain or re-export the .exr file from a trusted source/encoder (e.g. re-save with OpenEXR tooling) to rule out corruption.
  2. Verify the file transfers intact: compare byte size/checksum of the served asset against the original; ensure the server sends correct Content-Length and no text/error pages are decoded as EXR.
  3. Try loading the EXR without huf compression (export with zip/zip16/piz/rle compression) or convert to another supported format.
  4. Wrap the load in error handling and surface the message so users know the asset, not the app, is at fault.

Example fix

// before
scene.loadTexture('render.exr', ...); // throws if file is corrupt
// after
engine.onTextureLoadError = (msg) => console.warn('EXR asset invalid, using fallback:', msg);
scene.loadTexture('render.exr', onLoad, () => scene.loadTexture('render.png', onLoad));
Defensive patterns

Strategy: try-catch

Validate before calling

async function isValidExr(url) {
  const res = await fetch(url);
  const buf = new Uint8Array(await res.arrayBuffer());
  if (buf.length < 8) return false;
  const magic = 20000630; // OpenEXR magic number
  const view = new DataView(buf.buffer);
  return view.getUint32(0, true) === magic && buf.length >= res.headers.get('content-length') * 1 || view.getUint32(0, true) === magic;
}
// call before loading: if (!(await isValidExr(url))) useFallbackTexture();

Type guard

function isExrBuffer(data) {
  return data instanceof ArrayBuffer &&
    data.byteLength >= 8 &&
    new DataView(data).getUint32(0, true) === 20000630;
}

Try / catch

try {
  const texture = await scene.loadTextureAsync('render.exr');
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid table entry') {
    console.error('EXR huf data is corrupt; re-export the asset without huf compression.');
    useFallbackTexture();
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Loading a huf-compressed EXR file whose huf code table decodes to a symbol whose code value exceeds its declared bit length — i.e. the compressed stream or its header (im..iM code entries) is corrupt, truncated, or was not produced by a valid huf encoder.

Common situations: Corrupted or partially downloaded .exr files; hand-edited or re-wrapped EXR files; files produced by buggy third-party EXR writers; serving EXR assets through a proxy/CDN that truncates or re-encodes binary data; loading a non-huf or damaged EXR with LoadTextures/EXRLoader.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/99f335cc8b689dd4. Report an issue: GitHub.