BabylonJS/Babylon.js · error · Error
Invalid frame count line
Error message
Invalid frame count line
What it means
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).
Source
Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:362
const nodeLine = lines.shift();
if (!nodeLine) {
throw new Error("Unexpected end of file after HIERARCHY");
}
const root = ReadNode(lines, nodeLine.trim(), null, context);
// read motion data
const motionLine = lines.shift();
if (!motionLine || motionLine.trim().toUpperCase() !== _MotionNode) {
throw new Error("MOTION expected");
}
const framesLine = lines.shift();
if (!framesLine) {
throw new Error("Unexpected end of file before frame count");
}
const framesTokens = framesLine.trim().split(/[\s]+/);
if (framesTokens.length < 2) {
throw new Error("Invalid frame count line");
}
// number of frames
const numFrames = parseInt(framesTokens[1]);
if (isNaN(numFrames)) {
throw new Error("Failed to read number of frames.");
}
context.numFrames = numFrames;
// frame time
const frameTimeLine = lines.shift();
if (!frameTimeLine) {
throw new Error("Unexpected end of file before frame time");
}
const frameTimeTokens = frameTimeLine.trim().split(/[\s]+/);
if (frameTimeTokens.length < 3) {
throw new Error("Invalid frame time line");
}View on GitHub (pinned to 0592b347b8)
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.
Example fix
// before MOTION Frames: Frame Time: 0.033333 // after MOTION Frames: 120 Frame Time: 0.033333
Defensive patterns
Strategy: validation
Validate before calling
function parseFrameCount(text: string): number | null {
const m = text.match(/MOTION\s*\n\s*Frames:\s*(\S+)/i);
if (!m) return null;
const n = parseInt(m[1], 10);
return Number.isNaN(n) ? null : n;
}
const frameCount = parseFrameCount(bvhText);
if (frameCount === null) throw new Error("BVH 'Frames:' line is missing its numeric count"); Try / catch
try {
const skeleton = ReadBvh(bvhText, scene, null, options);
} catch (e) {
if (e instanceof Error && e.message === "Invalid frame count line") {
console.error("Line after MOTION is not 'Frames: <n>'", e);
} else {
throw e;
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to read number of frames.
- Unexpected end of file after HIERARCHY
- MOTION expected
- Unexpected end of file before frame count
- Expected opening { after type & name
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/b6975c819392b2e5.
Report an issue: GitHub.