BabylonJS/Babylon.js · error · Error
Unexpected end of file before frame count
Error message
Unexpected end of file before frame count
What it means
Immediately after the MOTION keyword, a valid BVH file must contain a 'Frames: <count>' line. ReadBvh shifts the next line after MOTION and throws this error when that line is undefined — the text ended right after MOTION with no frame-count line at all. The parser needs the frame count to know how many motion data lines to read, so it cannot continue.
Source
Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:358
if (!firstLine || firstLine.trim().toUpperCase() !== _HierarchyNode) {
throw new Error("HIERARCHY expected");
}
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");
}View on GitHub (pinned to 0592b347b8)
Solutions
- Verify the file is complete: after MOTION there must be a 'Frames: <n>' line followed by 'Frame Time:' and n data lines; re-download or re-export.
- Check file size against the source; a truncated transfer is the most common cause — retry the download.
- If generating BVH in code, append the 'Frames: N' and 'Frame Time: t' headers after MOTION.
- Log the last lines of the text passed to ReadBvh (text.split('\n').slice(-5)) to confirm truncation before calling.
- Validate with /MOTION\s*\n\s*Frames:\s*\d+/ before calling ReadBvh.
Example fix
// before MOTION // EOF here -> error // after MOTION Frames: 60 Frame Time: 0.033333 <60 lines of frame data>
Defensive patterns
Strategy: validation
Validate before calling
function hasFramesHeader(text: string): boolean {
return /MOTION\s*\n\s*Frames:\s*\d+/i.test(text);
}
if (!hasFramesHeader(bvhText)) {
throw new Error("BVH file truncated before 'Frames:' line");
}
const skeleton = ReadBvh(bvhText, scene, null, options); Try / catch
try {
const skeleton = ReadBvh(bvhText, scene, null, options);
} catch (e) {
if (e instanceof Error && e.message.includes("before frame count")) {
console.error("BVH ends right after MOTION — file truncated", e);
} else {
throw e;
}
} Prevention
- Verify downloaded file sizes/checksums; truncation between MOTION and Frames: is typical of interrupted transfers.
- When generating BVH strings, always append the Frames/Frame Time headers before writing.
- Inspect the tail of the file (last 3 lines) in CI before shipping motion assets.
When it happens
Trigger: Calling ReadBvh with text that ends exactly at the 'MOTION' line (nothing after it), a file truncated between 'MOTION' and 'Frames:', or passing a string that was sliced/trimmed so trailing lines were dropped before the call.
Common situations: Truncated downloads or uploads (file cut off mid-write), server responses cut at a content-length boundary, text editors or scripts that stripped trailing lines, or generating BVH programmatically and forgetting to append the 'Frames:' header and frame data.
Related errors
- Unexpected end of file after HIERARCHY
- Unexpected end of file: missing OFFSET
- Unexpected end of file: missing CHANNELS
- Unexpected end of file: missing closing brace
- MOTION expected
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/c9a044e18d9401d2.
Report an issue: GitHub.