{"record":{"id":"b409cda5ade8b2ad","repo":"BabylonJS/Babylon.js","slug":"expected-offset-but-got","errorCode":null,"errorMessage":"Expected OFFSET, but got: ","messagePattern":"Expected OFFSET, but got: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/BVH/bvhLoader.ts","lineNumber":271,"sourceCode":"    } else {\n        node.name = tokens[1];\n        node.type = tokens[0].toUpperCase();\n    }\n\n    // opening bracket\n    if (lines.shift()?.trim() != \"{\") {\n        throw new Error(\"Expected opening { after type & name\");\n    }\n\n    // parse OFFSET\n    const tokensSplit = lines.shift()?.trim().split(/\\s+/);\n    if (!tokensSplit) {\n        throw new Error(\"Unexpected end of file: missing OFFSET\");\n    }\n    tokens = tokensSplit;\n\n    if (tokens[0].toUpperCase() != \"OFFSET\") {\n        throw new Error(\"Expected OFFSET, but got: \" + tokens[0]);\n    }\n    if (tokens.length != 4) {\n        throw new Error(\"OFFSET: Invalid number of values\");\n    }\n\n    const offset = new Vector3(parseFloat(tokens[1]), parseFloat(tokens[2]), parseFloat(tokens[3]));\n\n    if (isNaN(offset.x) || isNaN(offset.y) || isNaN(offset.z)) {\n        throw new Error(\"OFFSET: Invalid values\");\n    }\n\n    node.offset = offset;\n\n    // parse CHANNELS definitions\n    if (node.type != \"ENDSITE\") {\n        tokens = lines.shift()?.trim().split(/\\s+/);\n        if (!tokens) {\n            throw new Error(\"Unexpected end of file: missing CHANNELS\");","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/BVH/bvhLoader.ts#L253-L289","documentation":"Each BVH node's first line inside its brace must start with the keyword OFFSET. When the parser reads a line that is not OFFSET (it echoes the offending token into the message), it throws, because the required channel-offset declaration is missing or out of order.","triggerScenarios":"A node body where CHANNELS, JOINT, \"}\", or any other token appears before OFFSET; swapped lines such as \"CHANNELS 6 Xrotation ...\" placed before OFFSET; a name line accidentally pasted inside the node body.","commonSituations":"Hand-edited BVH files with reordered lines; exports from custom/buggy tooling that writes CHANNELS before OFFSET; line-alignment drift when files are processed by scripts that re-sort or dedent lines.","solutions":["Open the .bvh and confirm each node body starts with \"OFFSET x y z\" before any CHANNELS line — move misplaced lines into position.","Re-export the BVH from the source DCC/mocap tool instead of hand-editing.","Check the reported offending token in the message to locate the bad line quickly.","If a script transforms your BVH, fix its line ordering or validate output against the BVH spec."],"exampleFix":"// before (malformed)\nROOT Hips\n{\n  CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation\n  OFFSET 0.0 0.0 0.0\n// after (valid)\nROOT Hips\n{\n  OFFSET 0.0 0.0 0.0\n  CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation","handlingStrategy":"validation","validationCode":"function assertOffsetFirstInsideNodes(text: string): void {\n  const lines = text.split(/\\r?\\n/).map((l) => l.trim());\n  let expectOffset = false;\n  lines.forEach((line, i) => {\n    const t = line.toUpperCase();\n    if (/^(ROOT|JOINT)\\s/.test(t) || t === \"END SITE\") { expectOffset = true; return; }\n    if (expectOffset) {\n      if (line !== \"{\") throw new Error(`Line ${i + 1}: expected {`);\n      expectOffset = false;\n      // next non-brace line must be OFFSET\n      const next = lines[i + 1];\n      if (next && !next.toUpperCase().startsWith(\"OFFSET\")) {\n        throw new Error(`Line ${i + 2}: expected OFFSET, got \"${next.split(/\\s+/)[0]}\"`);\n      }\n    }\n  });\n}","typeGuard":null,"tryCatchPattern":"try {\n  const skeleton = ReadBvh(text, scene, null, options);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Expected OFFSET\")) {\n    console.error(\"BVH node body is out of order: OFFSET must come first inside each node.\");\n  } else { throw e; }\n}","preventionTips":["Keep node body order fixed: OFFSET then CHANNELS then children.","Re-export BVH files instead of editing them by hand.","Use the error's echoed token to find the offending line fast."],"tags":["bvh","parser","file-format","malformed-input"],"backgroundTag":"malformed-bvh-structure","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}