{"record":{"id":"b6975c819392b2e5","repo":"BabylonJS/Babylon.js","slug":"invalid-frame-count-line","errorCode":null,"errorMessage":"Invalid frame count line","messagePattern":"Invalid frame count line","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/BVH/bvhLoader.ts","lineNumber":362,"sourceCode":"    const nodeLine = lines.shift();\n    if (!nodeLine) {\n        throw new Error(\"Unexpected end of file after HIERARCHY\");\n    }\n    const root = ReadNode(lines, nodeLine.trim(), null, context);\n\n    // read motion data\n    const motionLine = lines.shift();\n    if (!motionLine || motionLine.trim().toUpperCase() !== _MotionNode) {\n        throw new Error(\"MOTION expected\");\n    }\n\n    const framesLine = lines.shift();\n    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    }","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/BVH/bvhLoader.ts#L344-L380","documentation":"The line following MOTION must be a frame-count declaration of the form 'Frames: <count>' — at least two whitespace-separated tokens. ReadBvh splits the line on whitespace and throws this error when fewer than 2 tokens are present, meaning the line exists but does not carry a frame count value (or the line is blank/garbage).","triggerScenarios":"Calling ReadBvh where the line after MOTION is 'Frames:' with no number, just a bare number like '120' without the 'Frames:' keyword plus a value counted... more precisely: a line such as 'Frames' (one token), an empty/whitespace-only line, or a stray line inserted between MOTION and the actual 'Frames:' line so the wrong line is parsed.","commonSituations":"Hand-edited BVH files where the count was deleted or the colon/number dropped, generators emitting 'MOTION' followed by a blank line instead of 'Frames: N', locale/tool variants writing 'Frames' without the count, or files where an extra blank-ish line shifted parsing.","solutions":["Ensure the line right after MOTION reads exactly 'Frames: <integer>' (e.g. 'Frames: 120'); fix or re-export the file.","Remove blank or stray lines between MOTION and the Frames line — the parser consumes lines positionally, not by scanning.","If generating BVH in code, always emit `Frames: ${numFrames}` with the count on the same line.","Check the file wasn't processed by a script that collapsed whitespace or dropped tokens; compare against a known-good BVH.","Pre-validate with /MOTION\\s*\\n\\s*Frames:\\s+\\d+/ before calling ReadBvh."],"exampleFix":"// before\nMOTION\nFrames:\nFrame Time: 0.033333\n\n// after\nMOTION\nFrames: 120\nFrame Time: 0.033333","handlingStrategy":"validation","validationCode":"function parseFrameCount(text: string): number | null {\n    const m = text.match(/MOTION\\s*\\n\\s*Frames:\\s*(\\S+)/i);\n    if (!m) return null;\n    const n = parseInt(m[1], 10);\n    return Number.isNaN(n) ? null : n;\n}\nconst frameCount = parseFrameCount(bvhText);\nif (frameCount === null) throw new Error(\"BVH 'Frames:' line is missing its numeric count\");","typeGuard":null,"tryCatchPattern":"try {\n    const skeleton = ReadBvh(bvhText, scene, null, options);\n} catch (e) {\n    if (e instanceof Error && e.message === \"Invalid frame count line\") {\n        console.error(\"Line after MOTION is not 'Frames: <n>'\", e);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep the canonical 'Frames: <int>' format — one line, colon, integer.","Strip blank lines between MOTION and Frames: before parsing if you preprocess the text.","Test generated BVH output against a reference parser or golden file in CI."],"tags":["bvh","parser","mocap","malformed-header"],"backgroundTag":"bvh-malformed-file","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}