BabylonJS/Babylon.js · error · Error

Unexpected end of file: missing OFFSET

Error message

Unexpected end of file: missing OFFSET

What it means

After the opening "{" of a BVH node, the format requires an OFFSET line with three floats. If the parser reaches end-of-input while trying to read that line (lines.shift() returns undefined, so trim/split is not possible), this error is thrown — the file simply ended before the OFFSET line.

Source

Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:266

    let tokens: string[] | undefined = firstLine.trim().split(/\s+/);

    if (tokens[0].toUpperCase() === "END" && tokens[1].toUpperCase() === "SITE") {
        node.type = "ENDSITE";
        node.name = "ENDSITE"; // bvh end sites have no name
    } else {
        node.name = tokens[1];
        node.type = tokens[0].toUpperCase();
    }

    // opening bracket
    if (lines.shift()?.trim() != "{") {
        throw new Error("Expected opening { after type & name");
    }

    // parse OFFSET
    const tokensSplit = lines.shift()?.trim().split(/\s+/);
    if (!tokensSplit) {
        throw new Error("Unexpected end of file: missing OFFSET");
    }
    tokens = tokensSplit;

    if (tokens[0].toUpperCase() != "OFFSET") {
        throw new Error("Expected OFFSET, but got: " + tokens[0]);
    }
    if (tokens.length != 4) {
        throw new Error("OFFSET: Invalid number of values");
    }

    const offset = new Vector3(parseFloat(tokens[1]), parseFloat(tokens[2]), parseFloat(tokens[3]));

    if (isNaN(offset.x) || isNaN(offset.y) || isNaN(offset.z)) {
        throw new Error("OFFSET: Invalid values");
    }

    node.offset = offset;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Verify the file is complete: it should end with END SITE blocks, closing braces, a MOTION section and frame data — check the last line of the file.
  2. Re-download/re-copy the .bvh file and compare file sizes or hashes with the original source.
  3. If you generated the BVH programmatically, ensure every node writes OFFSET after the opening brace.
  4. Wrap the loader call in try/catch to surface a clear 'file appears truncated' message to users.
Defensive patterns

Strategy: validation

Validate before calling

function assertBvhComplete(text: string): void {
  const t = text.trim();
  if (!t.toUpperCase().includes("MOTION")) {
    throw new Error("BVH file appears truncated: no MOTION section found.");
  }
  const opens = (t.match(/\{/g) || []).length;
  const closes = (t.match(/\}/g) || []).length;
  if (opens !== closes) throw new Error("BVH braces unbalanced - file truncated.");
}

Type guard

function looksCompleteBvh(text: string): boolean {
  return /\bMOTION\b/i.test(text) &&
    (text.match(/\{/g) || []).length === (text.match(/\}/g) || []).length;
}

Try / catch

try {
  const skeleton = ReadBvh(text, scene, null, options);
} catch (e) {
  if (e instanceof Error && e.message.includes("Unexpected end of file")) {
    console.error("BVH file is truncated; re-download it.");
  } else { throw e; }
}

Prevention

When it happens

Trigger: Loading a .bvh file that ends right after a node's "{" line: a truncated download, a file saved mid-write, or a hierarchy whose final JOINT block is cut off before OFFSET.

Common situations: Partially uploaded/downloaded motion-capture files; git LFS or text-mode transfer truncation; hand-trimming files for testing and accidentally deleting lines; concatenating files incorrectly.

Related errors


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