{"record":{"id":"83b2c174f1963e3c","repo":"BabylonJS/Babylon.js","slug":"ascii-fbx-array-declared-count-values-but-parse","errorCode":null,"errorMessage":"ASCII FBX array declared ${count} values but parsed ${values.length}","messagePattern":"ASCII FBX array declared (.+?) values but parsed (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/fbxAsciiParser.ts","lineNumber":351,"sourceCode":"    const values: number[] = [];\r\n    while (true) {\r\n        const peek = tokenizer.peek();\r\n        if (peek.type === TokenType.CloseBrace || peek.type === TokenType.EOF) {\r\n            break;\r\n        }\r\n        if (peek.type === TokenType.Comma) {\r\n            tokenizer.next();\r\n            continue;\r\n        }\r\n        if (peek.type === TokenType.Number) {\r\n            const tok = tokenizer.next();\r\n            values.push(Number(tok.value));\r\n        } else {\r\n            break;\r\n        }\r\n    }\r\n    if (values.length !== count) {\r\n        throw new Error(`ASCII FBX array declared ${count} values but parsed ${values.length}`);\r\n    }\r\n    return values;\r\n}\r\n\r\nfunction parseNumericValue(str: string): number {\r\n    return Number(str);\r\n}\r\n\r\nfunction isInt32(value: number): boolean {\r\n    return value >= -2147483648 && value <= 2147483647;\r\n}\r\n","sourceCodeStart":333,"sourceCodeEnd":363,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/fbxAsciiParser.ts#L333-L363","documentation":"ASCII FBX array properties (`*N { a: v1,v2,... }`) declare the exact number of values N in the header. After consuming tokens the parser counts what it actually parsed; if the count mismatches the declared N the file is corrupt/inconsistent, so it throws rather than returning a mis-shaped typed array.","triggerScenarios":"Parsing an ASCII FBX via `values` (parseArrayValues) where the `*N` declared count differs from the comma-separated values actually present — e.g. declared `*24` but only 23 numbers before the closing brace, or trailing garbage breaks token consumption early.","commonSituations":"Truncated downloads of .fbx files; manual edits removing/adding values without updating the `*N` count; third-party exporters that write wrong array counts; float values containing characters the tokenizer rejects, ending value parsing early.","solutions":["Fix the declared count to match the number of values (`*23` if 23 values follow) or restore the missing values","Re-export the FBX from the original tool to regenerate a consistent file","Check for truncated/corrupted transfer — re-download or re-copy the file","Look for unparseable tokens (e.g. `NaN`, stray characters) right after the last parsed value"],"exampleFix":"// before (ASCII FBX)\nVertices: *3 {\n  a: 1,2\n}\n// after\nVertices: *3 {\n  a: 1,2,3\n}","handlingStrategy":"try-catch","validationCode":"// cheap pre-check: array headers and value counts\nfor (const m of text.matchAll(/\\*(\\d+)\\s*\\{([^}]*)\\}/g)) {\n  const declared = Number(m[1]);\n  const actual = m[2].split(',').filter(s => s.trim() !== '').length;\n  if (declared !== actual) throw new Error(`Array declares ${declared} but has ${actual}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const doc = parseAsciiFbx(text);\n} catch (e) {\n  if (/declared \\d+ values but parsed/.test(e.message)) {\n    console.error(\"FBX array count mismatch — file likely truncated or hand-edited; re-export it\");\n  } else throw e;\n}","preventionTips":["Verify file size/checksum after download before parsing","Avoid manual edits to `*N {...}` blocks; if editing, update N","Prefer binary FBX export over ASCII for pipeline assets","Reject empty/overshort files early (size sanity check)"],"tags":["fbx","parser","ascii","array","corrupt-file"],"backgroundTag":"fbx-parse-syntax-error","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}