{"record":{"id":"0a3f9eaae8cc3c91","repo":"BabylonJS/Babylon.js","slug":"unexpected-end-of-file-before-frame-time","errorCode":null,"errorMessage":"Unexpected end of file before frame time","messagePattern":"Unexpected end of file before frame time","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/BVH/bvhLoader.ts","lineNumber":375,"sourceCode":"    if (!framesLine) {\n        throw new Error(\"Unexpected end of file before frame count\");\n    }\n    const framesTokens = framesLine.trim().split(/[\\s]+/);\n    if (framesTokens.length < 2) {\n        throw new Error(\"Invalid frame count line\");\n    }\n\n    // number of frames\n    const numFrames = parseInt(framesTokens[1]);\n    if (isNaN(numFrames)) {\n        throw new Error(\"Failed to read number of frames.\");\n    }\n    context.numFrames = numFrames;\n\n    // frame time\n    const frameTimeLine = lines.shift();\n    if (!frameTimeLine) {\n        throw new Error(\"Unexpected end of file before frame time\");\n    }\n    const frameTimeTokens = frameTimeLine.trim().split(/[\\s]+/);\n    if (frameTimeTokens.length < 3) {\n        throw new Error(\"Invalid frame time line\");\n    }\n    const frameTime = parseFloat(frameTimeTokens[2]);\n    if (isNaN(frameTime)) {\n        throw new Error(\"Failed to read frame time.\");\n    }\n    if (frameTime <= 0) {\n        throw new Error(\"Failed to read frame time. Invalid value \" + frameTime);\n    }\n\n    context.frameRate = 1 / frameTime;\n\n    // read frame data line by line\n    for (let i = 0; i < numFrames; ++i) {\n        const frameLine = lines.shift();","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/BVH/bvhLoader.ts#L357-L393","documentation":"ReadBvh parses a BVH motion-capture file line by line. After the MOTION header it expects a 'Frame Time:' line, and this error is thrown when the lines array is exhausted before that line is found, meaning the file ends prematurely in the MOTION section.","triggerScenarios":"Calling ReadBvh (via skeleton) with a BVH file whose MOTION section is truncated: the Frame:, Frames:, or Frame Time: lines are missing because the file was cut off, saved incompletely, or the hierarchy consumed all lines.","commonSituations":"Partially downloaded or interrupted BVH transfers, files truncated by editors or version control, hand-edited BVH files where the frame-time line was deleted, or feeding a plain skeleton definition HIERARCHY-only file with no MOTION block.","solutions":["Open the BVH file and verify it contains the full MOTION section ending with 'Frame Time: <seconds>' followed by frame data lines","Re-download or re-export the BVH from the source application to get an untruncated file","Check the file size against the expected size from the exporter; if smaller, the transfer was interrupted","If generating BVH programmatically, ensure Frame Time line is emitted after the Frames: line"],"exampleFix":"// before (truncated file)\nMOTION\nFrames: 100\n// after (complete MOTION header)\nMOTION\nFrames: 100\nFrame Time: 0.033333","handlingStrategy":"validation","validationCode":"function validateBvhMotionHeader(text) {\n  const lines = text.split(/\\r?\\n/);\n  const motionIdx = lines.findIndex(l => /^MOTION/i.test(l.trim()));\n  if (motionIdx === -1) throw new Error('No MOTION section');\n  const rest = lines.slice(motionIdx + 1).map(l => l.trim()).filter(Boolean);\n  if (!/^Frames?:\\s+\\d+/i.test(rest[0] ?? '')) throw new Error('Missing Frames: line');\n  if (!/^Frame Time:\\s+\\d/i.test(rest[1] ?? '')) throw new Error('Missing/truncated Frame Time line');\n}","typeGuard":"function hasFrameTimeLine(text: string): boolean {\n  const m = text.slice(text.toUpperCase().indexOf('MOTION'));\n  return /^Frame Time:\\s+\\S+/im.test(m);\n}","tryCatchPattern":"try {\n  skeleton.readBvh(text);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Unexpected end of file before frame time') {\n    console.error('BVH file truncated in MOTION section; re-export the file');\n  } else throw e;\n}","preventionTips":["Validate the MOTION header (Frames: and Frame Time: lines) before parsing","Verify downloaded BVH file sizes/checksums to catch truncation","Never hand-delete lines near the end of BVH files; re-export instead","Test your BVH pipeline with a known-good reference file"],"tags":["bvh","parsing","malformed-file","mocap"],"backgroundTag":"truncated-file-parse-error","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}