BabylonJS/Babylon.js · error · Error
Unexpected end of file before frame time
Error message
Unexpected end of file before frame time
What it means
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.
Source
Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:375
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");
}
const frameTime = parseFloat(frameTimeTokens[2]);
if (isNaN(frameTime)) {
throw new Error("Failed to read frame time.");
}
if (frameTime <= 0) {
throw new Error("Failed to read frame time. Invalid value " + frameTime);
}
context.frameRate = 1 / frameTime;
// read frame data line by line
for (let i = 0; i < numFrames; ++i) {
const frameLine = lines.shift();View on GitHub (pinned to 0592b347b8)
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
Example fix
// before (truncated file) MOTION Frames: 100 // after (complete MOTION header) MOTION Frames: 100 Frame Time: 0.033333
Defensive patterns
Strategy: validation
Validate before calling
function validateBvhMotionHeader(text) {
const lines = text.split(/\r?\n/);
const motionIdx = lines.findIndex(l => /^MOTION/i.test(l.trim()));
if (motionIdx === -1) throw new Error('No MOTION section');
const rest = lines.slice(motionIdx + 1).map(l => l.trim()).filter(Boolean);
if (!/^Frames?:\s+\d+/i.test(rest[0] ?? '')) throw new Error('Missing Frames: line');
if (!/^Frame Time:\s+\d/i.test(rest[1] ?? '')) throw new Error('Missing/truncated Frame Time line');
} Type guard
function hasFrameTimeLine(text: string): boolean {
const m = text.slice(text.toUpperCase().indexOf('MOTION'));
return /^Frame Time:\s+\S+/im.test(m);
} Try / catch
try {
skeleton.readBvh(text);
} catch (e) {
if (e instanceof Error && e.message === 'Unexpected end of file before frame time') {
console.error('BVH file truncated in MOTION section; re-export the file');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid frame time line
- Unexpected end of file after HIERARCHY
- MOTION expected
- Unexpected end of file before frame count
- Invalid frame count line
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/0a3f9eaae8cc3c91.
Report an issue: GitHub.