{"record":{"id":"001139d0e46e077b","repo":"BabylonJS/Babylon.js","slug":"unexpected-end-of-file-missing-offset","errorCode":null,"errorMessage":"Unexpected end of file: missing OFFSET","messagePattern":"Unexpected end of file: missing OFFSET","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/BVH/bvhLoader.ts","lineNumber":266,"sourceCode":"    let tokens: string[] | undefined = firstLine.trim().split(/\\s+/);\n\n    if (tokens[0].toUpperCase() === \"END\" && tokens[1].toUpperCase() === \"SITE\") {\n        node.type = \"ENDSITE\";\n        node.name = \"ENDSITE\"; // bvh end sites have no name\n    } 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","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/BVH/bvhLoader.ts#L248-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Re-download/re-copy the .bvh file and compare file sizes or hashes with the original source.","If you generated the BVH programmatically, ensure every node writes OFFSET after the opening brace.","Wrap the loader call in try/catch to surface a clear 'file appears truncated' message to users."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertBvhComplete(text: string): void {\n  const t = text.trim();\n  if (!t.toUpperCase().includes(\"MOTION\")) {\n    throw new Error(\"BVH file appears truncated: no MOTION section found.\");\n  }\n  const opens = (t.match(/\\{/g) || []).length;\n  const closes = (t.match(/\\}/g) || []).length;\n  if (opens !== closes) throw new Error(\"BVH braces unbalanced - file truncated.\");\n}","typeGuard":"function looksCompleteBvh(text: string): boolean {\n  return /\\bMOTION\\b/i.test(text) &&\n    (text.match(/\\{/g) || []).length === (text.match(/\\}/g) || []).length;\n}","tryCatchPattern":"try {\n  const skeleton = ReadBvh(text, scene, null, options);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"Unexpected end of file\")) {\n    console.error(\"BVH file is truncated; re-download it.\");\n  } else { throw e; }\n}","preventionTips":["Verify file size/hash after download before parsing.","Check the file ends with frame data, not mid-node.","Never parse partially streamed BVH content."],"tags":["bvh","parser","truncated-file","malformed-input"],"backgroundTag":"malformed-bvh-structure","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}