BabylonJS/Babylon.js · error · Error
Unexpected end of file: missing closing brace
Error message
Unexpected end of file: missing closing brace
What it means
ReadNode consumes lines until it sees a closing "}" for the current node. If the input is exhausted before every opened brace is closed, the recursion cannot terminate cleanly and this error is thrown — the hierarchy section is unbalanced or truncated.
Source
Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:314
const numChannels = parseInt(tokens[1]);
// Skip CHANNELS and the number of channels
node.channels = tokens.splice(2, numChannels);
node.children = [];
}
// read children
while (lines.length > 0) {
const line = lines.shift()?.trim();
if (line === "}") {
// Finish reading the node
return node;
} else if (line) {
node.children.push(ReadNode(lines, line, node, context));
}
}
throw new Error("Unexpected end of file: missing closing brace");
}
/**
* Reads a BVH file, returns a skeleton
* @param text - The BVH file content
* @param scene - The scene to add the skeleton to
* @param assetContainer - The asset container to add the skeleton to
* @param loadingOptions - The loading options
* @returns The skeleton
*/
export function ReadBvh(text: string, scene: Scene, assetContainer: Nullable<AssetContainer>, loadingOptions: BVHLoadingOptions): Skeleton {
const lines = text.split("\n");
const { loopMode } = loadingOptions;
scene._blockEntityCollection = !!assetContainer;
const skeleton = new Skeleton("", "", scene);
skeleton._parentContainer = assetContainer;View on GitHub (pinned to 0592b347b8)
Solutions
- Count braces: the number of "{" lines must equal the number of "}" lines in the HIERARCHY section — add the missing closing brace(s).
- Check the file ends properly: after the hierarchy there should be a MOTION line followed by "Frames: n" and "Frame Time:" then frame data — a file ending mid-tree is truncated; re-download it.
- If hand-editing, re-indent the hierarchy (each nesting level inside one more brace) to spot the unclosed block visually.
- Validate the file with another BVH reader or the exporting tool before loading it here.
Example fix
// before (missing outer brace)
ROOT Hips
{
JOINT Spine
{
OFFSET 0 8 0
}
// after
ROOT Hips
{
JOINT Spine
{
OFFSET 0 8 0
}
} Defensive patterns
Strategy: validation
Validate before calling
function assertBalancedBraces(text: string): void {
const hierarchy = text.toUpperCase().split("MOTION")[0];
const opens = (hierarchy.match(/\{/g) || []).length;
const closes = (hierarchy.match(/\}/g) || []).length;
if (opens !== closes) {
throw new Error(`Unbalanced braces in HIERARCHY: ${opens} open vs ${closes} close.`);
}
} Type guard
function hasBalancedBvhHierarchy(text: string): boolean {
const h = text.toUpperCase().split("MOTION")[0];
return (h.match(/\{/g) || []).length === (h.match(/\}/g) || []).length;
} Try / catch
try {
const skeleton = ReadBvh(text, scene, null, options);
} catch (e) {
if (e instanceof Error && e.message.includes("missing closing brace")) {
console.error("BVH hierarchy has an unclosed node block or is truncated.");
} else { throw e; }
} Prevention
- Count { and } equality before parsing.
- Check the file ends with frame data, not mid-hierarchy.
- Indent BVH hierarchies when editing so unclosed blocks are visible.
When it happens
Trigger: A .bvh file with more "{" than "}": a JOINT block missing its final brace, or the entire HIERARCHY section cut off mid-tree before the MOTION keyword; nested joints whose inner braces are balanced but whose outermost ROOT brace is never closed.
Common situations: Files truncated during download or by line-count-limited preview tools; manual edits deleting a "}" line; concatenating a hierarchy with frame data incorrectly so the closing brace is lost; badly written BVH generators.
Related errors
- Unexpected end of file: missing OFFSET
- Unexpected end of file: missing CHANNELS
- Expected opening { after type & name
- Expected OFFSET, but got:
- OFFSET: Invalid number of values
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/688cae8c62996ced.
Report an issue: GitHub.