BabylonJS/Babylon.js · error

zlib: preset dictionary not supported

Error message

zlib: preset dictionary not supported

What it means

A zlib FLG byte with bit 0x20 set declares a preset dictionary (FDICT flag). This lightweight one-shot inflater does not implement preset dictionaries and throws immediately. FBX files should never use preset dictionaries, so encountering one indicates unusual or hand-modified compressed data.

Source

Thrown at packages/dev/loaders/src/FBX/parsers/zlibInflate.ts:31

 *
 * This implementation is intentionally scoped to FBX binary array payloads: one-shot,
 * synchronous zlib streams with the exact uncompressed length known up front.
 */
export function inflateZlib(input: Uint8Array, expectedLength: number): Uint8Array {
    if (!Number.isInteger(expectedLength) || expectedLength < 0) {
        throw new Error("zlib: invalid expected length");
    }
    if (input.byteLength < 6) {
        throw new Error("zlib: unexpected end of input");
    }

    const cmf = input[0];
    const flg = input[1];
    if ((cmf & 0x0f) !== 8 || cmf >> 4 > 7 || ((cmf << 8) + flg) % 31 !== 0) {
        throw new Error("zlib: invalid header");
    }
    if ((flg & 0x20) !== 0) {
        throw new Error("zlib: preset dictionary not supported");
    }

    const reader = new BitReader(input, 2, input.byteLength - 4);
    const output = new OutputWriter(expectedLength);

    let isFinalBlock = false;
    while (!isFinalBlock) {
        isFinalBlock = reader.readBits(1) === 1;
        const blockType = reader.readBits(2);
        switch (blockType) {
            case 0:
                inflateStoredBlock(reader, output);
                break;
            case 1:
                inflateCompressedBlock(reader, output, getFixedLiteralLengthTree(), getFixedDistanceTree());
                break;
            case 2: {
                const { literalLengthTree, distanceTree } = readDynamicTrees(reader);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Recompress the payload with plain zlib (no dictionary) and rebuild or re-export the FBX
  2. Use a full zlib implementation (e.g., pako/DecompressionStream with dictionary support) if you must consume such data
  3. Confirm the exporter producing the FBX uses default zlib settings
Defensive patterns

Strategy: validation

Validate before calling

if ((compressed[1] & 0x20) !== 0) {
  throw new Error('FBX array uses zlib preset dictionary, which is unsupported');
}

Type guard

function usesPresetDictionary(b: Uint8Array): boolean {
  return b.byteLength >= 2 && (b[1] & 0x20) !== 0;
}

Try / catch

try {
  return inflateZlib(compressed, expectedLength);
} catch (e) {
  if ((e as Error).message === 'zlib: preset dictionary not supported') {
    throw new Error('Unsupported zlib dictionary in FBX array — re-export the asset', { cause: e });
  }
  throw e;
}

Prevention

When it happens

Trigger: parseArrayProperty inflating an FBX array payload whose zlib header has FDICT set — i.e., data compressed with zlib with a custom dictionary.

Common situations: Data compressed by a non-standard tool configured with a zlib dictionary; hand-crafted or post-processed FBX payloads; generic zlib data embedded into an FBX file by a custom pipeline.

Related errors


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