{"record":{"id":"9fb40df44c30d28d","repo":"BabylonJS/Babylon.js","slug":"hierarchy-expected","errorCode":null,"errorMessage":"HIERARCHY expected","messagePattern":"HIERARCHY expected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/BVH/bvhLoader.ts","lineNumber":341,"sourceCode":" * @returns The skeleton\n */\nexport function ReadBvh(text: string, scene: Scene, assetContainer: Nullable<AssetContainer>, loadingOptions: BVHLoadingOptions): Skeleton {\n    const lines = text.split(\"\\n\");\n\n    const { loopMode } = loadingOptions;\n\n    scene._blockEntityCollection = !!assetContainer;\n    const skeleton = new Skeleton(\"\", \"\", scene);\n    skeleton._parentContainer = assetContainer;\n    scene._blockEntityCollection = false;\n\n    const context = new LoaderContext(skeleton);\n    context.loopMode = loopMode;\n\n    // read model structure\n    const firstLine = lines.shift();\n    if (!firstLine || firstLine.trim().toUpperCase() !== _HierarchyNode) {\n        throw new Error(\"HIERARCHY expected\");\n    }\n\n    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    }","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/BVH/bvhLoader.ts#L323-L359","documentation":"ReadBvh expects the very first non-empty line of a BVH file to be the keyword \"HIERARCHY\" (case-insensitive). If the first line is missing or is anything else, the file is not recognized as BVH and this error is thrown before any node parsing begins.","triggerScenarios":"Passing a non-BVH file (FBX/glTF/JSON/XML, or an image) to the BVH loader; passing a file that starts with a BOM, comment, blank leading lines handled differently, or a motion-only snippet without its HIERARCHY header; file content arriving URL-encoded or base64-wrapped.","commonSituations":"Wrong file extension/asset type wired into the loader pipeline; download managers saving an HTML error page as .bvh; export tools writing a preamble comment before HIERARCHY; stripping the header when extracting only frame data.","solutions":["Open the file and confirm the first line is exactly \"HIERARCHY\" — remove any preamble (BOM, comments, HTML) before it or re-export the file.","Verify you are actually loading a BVH file; if the asset is another format, use the correct loader for it.","Re-download the file — a saved HTML error page or empty file will fail here.","Strip a UTF-8 BOM from the text before calling the loader if the source tool writes one."],"exampleFix":"// before\nconst text = await (await fetch(url)).text(); // may start with BOM\nskeleton = ReadBvh(text, scene, null, options);\n// after\nconst text = (await (await fetch(url)).text()).replace(/^\\uFEFF/, \"\").trimStart();\nif (!text.toUpperCase().startsWith(\"HIERARCHY\")) throw new Error(\"Not a BVH file\");\nskeleton = ReadBvh(text, scene, null, options);","handlingStrategy":"validation","validationCode":"function loadBvhSafely(raw: string): string {\n  const text = raw.replace(/^\\uFEFF/, \"\").trimStart();\n  if (!text.toUpperCase().startsWith(\"HIERARCHY\")) {\n    throw new Error(\"Not a BVH file: expected HIERARCHY header.\");\n  }\n  return text;\n}\n// then: ReadBvh(loadBvhSafely(rawText), scene, null, options);","typeGuard":"function isBvhText(text: string): boolean {\n  return text.replace(/^\\uFEFF/, \"\").trimStart().toUpperCase().startsWith(\"HIERARCHY\");\n}","tryCatchPattern":"try {\n  const skeleton = ReadBvh(text, scene, null, options);\n} catch (e) {\n  if (e instanceof Error && e.message === \"HIERARCHY expected\") {\n    console.error(\"This file is not a valid BVH file (missing HIERARCHY header).\");\n  } else { throw e; }\n}","preventionTips":["Verify the asset type/extension before routing it to the BVH loader.","Strip UTF-8 BOM and leading whitespace before parsing.","Check that downloaded .bvh files are not HTML error pages."],"tags":["bvh","parser","file-format","wrong-input"],"backgroundTag":"malformed-bvh-structure","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}