BabylonJS/Babylon.js · error
deflate: invalid code length repeat
Error message
deflate: invalid code length repeat
What it means
Code-length symbol 16 repeats the previous code length 3-6 times, which is illegal when there is no previous length (it would be the very first decoded entry). This throw means the dynamic block's code-length sequence starts (or resumes) with a repeat-before-any-value pattern, indicating corrupt bitstream or misaligned reading.
Source
Thrown at packages/dev/loaders/src/FBX/parsers/zlibInflate.ts:378
distanceTree: new HuffmanTree(distanceLengths, { allowEmpty: true }),
};
}
function readCodeLengths(reader: BitReader, codeLengthTree: HuffmanTree, count: number): number[] {
const lengths: number[] = [];
while (lengths.length < count) {
const symbol = codeLengthTree.decode(reader);
if (symbol <= 15) {
lengths.push(symbol);
continue;
}
let repeatLength: number;
let repeatedValue: number;
switch (symbol) {
case 16:
if (lengths.length === 0) {
throw new Error("deflate: invalid code length repeat");
}
repeatedValue = lengths[lengths.length - 1];
repeatLength = reader.readBits(2) + 3;
break;
case 17:
repeatedValue = 0;
repeatLength = reader.readBits(3) + 3;
break;
case 18:
repeatedValue = 0;
repeatLength = reader.readBits(7) + 11;
break;
default:
throw new Error("deflate: invalid code length symbol");
}
if (lengths.length + repeatLength > count) {
throw new Error("deflate: invalid code length repeat");
View on GitHub (pinned to 0592b347b8)
Solutions
- Test the extracted payload with python zlib.decompress — if it fails there too, the file is corrupt and must be re-exported/re-downloaded
- Verify the property-header parsing produces the correct payload offset (payload must begin at the zlib header, immediately after the array length/encoding fields)
- Check the file's byte size against the exporter's output to detect truncation
- Compare behavior against the same asset exported without compression (FBX Encoding=0) to isolate the inflater
Defensive patterns
Strategy: validation
Validate before calling
// Verify payload is well-formed zlib before custom inflation
const ref = decompressSync(payload); // throws if corrupt
if (ref.byteLength !== expectedLength) throw new Error("Decoded size mismatch"); Try / catch
try {
const out = inflateZlib(payload, expectedLength);
} catch (e) {
if (e instanceof Error && e.message === "deflate: invalid code length repeat") {
throw new Error("FBX compressed array corrupt (bad code-length repeat)", { cause: e });
}
throw e;
} Prevention
- Validate offsets: payload must start at the zlib CMF byte, not inside the property header
- Re-download files whose size differs from the source manifest
- Run one golden FBX file through the loader in CI to catch parser regressions
When it happens
Trigger: readCodeLengths (called from readDynamicTrees during inflateZlib) decodes symbol 16 from the codeLengthTree when lengths.length === 0 — no prior code length exists to repeat.
Common situations: Corrupt FBX files; payload sliced from the wrong offset so the code-length tree is decoded from garbage; truncated downloads losing part of the dynamic header.
Related errors
- deflate: missing end-of-block code
- deflate: invalid code length symbol
- deflate: invalid huffman code
- deflate: invalid stored block length
- deflate: invalid literal/length symbol
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/48b33b05fd47e28c.
Report an issue: GitHub.