BabylonJS/Babylon.js · error · Error

OFFSET: Invalid number of values

Error message

OFFSET: Invalid number of values

What it means

An OFFSET line in BVH must contain exactly four whitespace-separated tokens: the keyword OFFSET plus three numeric components. When the parser counts a token list whose length is not 4, it throws, rejecting the offset declaration as structurally invalid.

Source

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

    }

    // 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;

    // parse CHANNELS definitions
    if (node.type != "ENDSITE") {
        tokens = lines.shift()?.trim().split(/\s+/);
        if (!tokens) {
            throw new Error("Unexpected end of file: missing CHANNELS");
        }

        if (tokens[0].toUpperCase() != "CHANNELS") {

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Locate the OFFSET line (the message gives no token, so search each node body) and make it read exactly "OFFSET x y z" with three floats.
  2. Check for CR-only (old Mac) line endings — normalize the file to LF/CRLF so each directive stays on its own line.
  3. Re-export from the original tool rather than editing in spreadsheet/word-processor software.
  4. If a converter produced the file, fix its OFFSET writer to always emit three values.

Example fix

// before
OFFSET 0.0 0.0 0.0 CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation
// after
OFFSET 0.0 0.0 0.0
CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation
Defensive patterns

Strategy: validation

Validate before calling

function assertOffsetTokenCounts(text: string): void {
  for (const line of text.split(/\r?\n/)) {
    const t = line.trim();
    if (t.toUpperCase().startsWith("OFFSET")) {
      const n = t.split(/\s+/).length;
      if (n !== 4) throw new Error(`Bad OFFSET (expected 4 tokens, got ${n}): "${t}"`);
    }
  }
}

Type guard

function isValidOffsetLine(line: string): boolean {
  const t = line.trim().split(/\s+/);
  return t.length === 4 && t[0].toUpperCase() === "OFFSET";
}

Try / catch

try {
  const skeleton = ReadBvh(text, scene, null, options);
} catch (e) {
  if (e instanceof Error && e.message === "OFFSET: Invalid number of values") {
    console.error("An OFFSET line does not have exactly 3 coordinates.");
  } else { throw e; }
}

Prevention

When it happens

Trigger: OFFSET lines with missing or extra components, e.g. "OFFSET 0 0" (one value dropped), "OFFSET 0.0 0.0 0.0 0.0" (extra value), or an OFFSET line accidentally merged with the following CHANNELS line by a text-processing step that collapsed newlines.

Common situations: Files edited in spreadsheet tools that drop trailing zeros/columns; custom exporters writing wrong column counts; scripts joining lines (CRLF/CR-only line endings that the split("\n") parser mishandles, merging OFFSET and CHANNELS into one line).

Related errors


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