{"record":{"id":"ba82effef3a728f1","repo":"BabylonJS/Babylon.js","slug":"hufdecode-issues","errorCode":null,"errorMessage":"hufDecode issues","messagePattern":"hufDecode issues","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts","lineNumber":363,"sourceCode":"\r\n        c = gc.c;\r\n        lc = gc.lc;\r\n\r\n        while (lc >= HUF_DECBITS) {\r\n            const index = (c >> (lc - HUF_DECBITS)) & HUF_DECMASK;\r\n            const pl = decodingTable[index];\r\n\r\n            if (pl.len) {\r\n                lc -= pl.len;\r\n\r\n                const gCode = GetCode(pl.lit, rlc, c, lc, array, offset, outBuffer, outOffset, outBufferEndOffset);\r\n                if (gCode) {\r\n                    c = gCode.c;\r\n                    lc = gCode.lc;\r\n                }\r\n            } else {\r\n                if (!pl.p) {\r\n                    throw new Error(\"hufDecode issues\");\r\n                }\r\n\r\n                let j;\r\n\r\n                for (j = 0; j < pl.lit; j++) {\r\n                    const l = HufLength(encodingTable[pl.p[j]]);\r\n\r\n                    while (lc < l && offset.value < inOffsetEnd) {\r\n                        gc = GetChar(c, lc, array, offset);\r\n\r\n                        c = gc.c;\r\n                        lc = gc.lc;\r\n                    }\r\n\r\n                    if (lc >= l) {\r\n                        if (HufCode(encodingTable[pl.p[j]]) == ((c >> (lc - l)) & ((1 << l) - 1))) {\r\n                            lc -= l;\r\n\r","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts#L345-L381","documentation":"In HufDecode, when the fetched table entry has no direct literal but also has no overflow pointer (`pl.p` is falsy), the decoder has no valid way to continue interpreting the bitstream — the table lookup hit an empty/inconsistent entry — so it throws \"hufDecode issues\". This indicates the huf bitstream does not match the decode table built from the same file.","triggerScenarios":"Bitstream of a huf-compressed EXR block runs into an unpopulated decode-table entry mid-decode: the compressed payload is truncated, offset-corrupted, or the header-declared data sizes don't match the actual data.","commonSituations":"EXR files cut off mid-scanline; offsets corrupted by byte-level data mangling; wrong chunk data lengths from a bad writer; reading a file where huf payload doesn't match its huf code table (e.g. file spliced from two versions).","solutions":["Replace the EXR asset with an intact copy; verify with checksum against the source.","Re-export the file with a standard OpenEXR writer, ideally with zip or piz compression instead of huf.","Ensure no server/proxy modifies the payload (disable transform/rewrite rules for .exr).","Handle the throw at load time and fall back to a re-encoded texture."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"async function exrLooksComplete(url) {\n  const res = await fetch(url, { headers: { Range: 'bytes=-8' } });\n  if (!res.ok) return false;\n  const tail = new Uint8Array(await res.arrayBuffer());\n  return tail.length === 8; // presence of terminal offset table bytes suggests an untruncated file\n}","typeGuard":"function isExrBuffer(data) {\n  return data instanceof ArrayBuffer &&\n    data.byteLength >= 8 &&\n    new DataView(data).getUint32(0, true) === 20000630;\n}","tryCatchPattern":"try {\n  const tex = await loadExrTexture(url);\n} catch (e) {\n  if (e instanceof Error && (e.message === 'hufDecode issues' || e.message === 'Invalid table entry')) {\n    showUserError('This EXR file is damaged and cannot be rendered.');\n    useFallbackTexture();\n  } else { throw e; }\n}","preventionTips":["Detect truncated downloads via Content-Length comparison before loading.","Convert critical EXRs to a web-friendly format (KTX2/Basis) at build time.","Never splice or hand-edit EXR files; always round-trip through a writer.","Retry failed loads against a re-exported copy, not the same bytes."],"tags":["exr","huf-decompression","corrupt-data","texture-loading"],"backgroundTag":"exr-huf-invalid-table-entry","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}