{"record":{"id":"1a4f516df7262e3a","repo":"BabylonJS/Babylon.js","slug":"unsafe-fbx-object-id-value-tostring-object-i","errorCode":null,"errorMessage":"Unsafe FBX object ID ${value.toString()}: object IDs must be safe integers.","messagePattern":"Unsafe FBX object ID (.+?): object IDs must be safe integers\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/types/fbxTypes.ts","lineNumber":85,"sourceCode":"/** Extract a property value by index, with type narrowing */\r\nexport function getPropertyValue<T extends FBXPropertyValue>(node: FBXNode, index: number): T | undefined {\r\n    if (index < node.properties.length) {\r\n        return node.properties[index].value as T;\r\n    }\r\n    return undefined;\r\n}\r\n\r\n/**\r\n * Converts an FBX object ID value to a safe JavaScript number.\r\n * @param value - Parsed FBX object ID value\r\n * @returns The object ID, or undefined when the value is not numeric\r\n */\r\nexport function getSafeFBXObjectId(value: unknown): number | undefined {\r\n    if (typeof value !== \"number\") {\r\n        return undefined;\r\n    }\r\n    if (!Number.isSafeInteger(value)) {\r\n        throw new Error(`Unsafe FBX object ID ${value.toString()}: object IDs must be safe integers.`);\r\n    }\r\n    return value;\r\n}\r\n\r\n/** Get the numeric ID from a node (first property is typically the int64 UID) */\r\nexport function getNodeId(node: FBXNode): number | undefined {\r\n    const prop = node.properties[0];\r\n    if (prop && (prop.type === \"int64\" || prop.type === \"int32\")) {\r\n        return getSafeFBXObjectId(prop.value);\r\n    }\r\n    return undefined;\r\n}\r\n\r\n/**\r\n * Clean FBX object names.\r\n * FBX names may contain:\r\n *   - A \"Class::\" prefix (e.g. \"Model::valkyrie_mesh\") — strip it\r\n *   - A binary null/control-character class suffix — strip it\r","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/types/fbxTypes.ts#L67-L103","documentation":"FBX object IDs are int64 values, but this library represents them as JS numbers and only accepts values within the IEEE-754 safe-integer range (2^53-1). getSafeFBXObjectId throws when a numeric ID exceeds Number.MAX_SAFE_INTEGER (or is non-integral), because downstream comparisons and maps would silently lose precision. Non-number inputs return undefined instead of throwing.","triggerScenarios":"Calling getSafeFBXObjectId (directly or via toObjectNumber/getNodeId) with a number parsed from an FBX node whose int64 UID is larger than 9007199254740991.","commonSituations":"FBX files authored in tools that generate large 64-bit UIDs (common in modern exporters); hand-rolling parsers that convert node ID strings with Number() instead of BigInt.","solutions":["Validate/sanitize the source data: check IDs against Number.isSafeInteger before use.","If you control export, configure the exporter to emit smaller/sequential IDs.","If you must handle big IDs, adapt the code path to parse IDs with BigInt instead of number.","Return undefined instead of calling getSafeFBXObjectId when the value may be unsafe, and skip/repair that node."],"exampleFix":"// before\nconst id = getNodeId(node); // throws for huge int64 UIDs\n// after\nconst raw = Number(node.properties[0]);\nconst id = Number.isSafeInteger(raw) ? raw : undefined;\nif (id === undefined) console.warn(\"Skipping node with unsafe FBX ID\", raw);","handlingStrategy":"validation","validationCode":"const raw = node.properties?.[0];\nif (typeof raw !== \"number\" || !Number.isSafeInteger(raw)) {\n  throw new Error(`FBX node ID ${raw} is not a safe integer`);\n}","typeGuard":"function isSafeFBXId(value: unknown): value is number {\n  return typeof value === \"number\" && Number.isSafeInteger(value);\n}","tryCatchPattern":"let id: number | undefined;\ntry {\n  id = getNodeId(node);\n} catch (e) {\n  if (String(e.message).startsWith(\"Unsafe FBX object ID\")) {\n    console.warn(\"Skipping node with unsafe int64 ID\");\n    id = undefined;\n  } else throw e;\n}","preventionTips":["Check Number.isSafeInteger on any int64 value converted with Number() before using it as an ID.","Prefer parsing FBX int64 UIDs with BigInt when full precision is required.","Test your FBX pipeline with assets from multiple exporters (IDs vary wildly in magnitude).","Centralize ID conversion in one helper that handles the unsafe case once."],"tags":["fbx","int64","safe-integer","javascript"],"backgroundTag":"unsafe-integer-precision","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}