{"record":{"id":"5991c4599c032a46","repo":"BabylonJS/Babylon.js","slug":"invalid-color-type","errorCode":null,"errorMessage":"Invalid color type","messagePattern":"Invalid color type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.ts","lineNumber":203,"sourceCode":"function ToColor(value: any, expectedValue: string) {\n    if (value.getClassName().startsWith(\"Color\")) {\n        return value as unknown as Color3 | Color4;\n    }\n    if (expectedValue === \"Color3\") {\n        return new Color3(value.x, value.y, value.z);\n    } else if (expectedValue === \"Color4\") {\n        return new Color4(value.x, value.y, value.z, value.w);\n    }\n    return value;\n}\n\nfunction FromColor(value: Color3 | Color4): Vector3 | Vector4 {\n    if (value instanceof Color3) {\n        return new Vector3(value.r, value.g, value.b);\n    } else if (value instanceof Color4) {\n        return new Vector4(value.r, value.g, value.b, value.a);\n    }\n    throw new Error(\"Invalid color type\");\n}\n\nlet _Registered = false;\n/**\n * Register side effects for flowGraphJsonPointerParserBlock.\n * Safe to call multiple times; only the first call has an effect.\n */\nexport function RegisterFlowGraphJsonPointerParserBlock(): void {\n    if (_Registered) {\n        return;\n    }\n    _Registered = true;\n\n    RegisterClass(FlowGraphBlockNames.JsonPointerParser, FlowGraphJsonPointerParserBlock);\n}\n","sourceCodeStart":185,"sourceCodeEnd":219,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.ts#L185-L219","documentation":"FromColor converts Color3/Color4 values to Vector3/Vector4 when a JSON pointer resolves into a color property. If the value is neither instanceof Color3 nor Color4, it throws 'Invalid color type'. This guards against values that merely look like colors (plain objects, RGBA arrays) but are not Babylon color instances.","triggerScenarios":"A JSON pointer resolves to an object created via JSON.parse or a plain literal {r,g,b} that is structurally a color but not a Color3/Color4 instance, so both instanceof checks fail.","commonSituations":"Colors loaded from serialized JSON/scene files without reconstruction; passing arrays like [1,0,0] where Color3 expected; cross-realm or duplicated-module Color3 classes defeating instanceof.","solutions":["Reconstruct the value as Color3/Color4 (e.g. new Color3(r,g,b)) before the pointer parser reads it","If the value comes from JSON, convert it: Color3.FromArray or manual construction at load time","Extend the accessor to normalize plain {r,g,b(,a)} objects into Color3/Color4 before calling FromColor"],"exampleFix":"// before\nconst value = JSON.parse('{\"r\":1,\"g\":0,\"b\":0}'); // plain object -> throws\n// after\nconst value = Color3.FromArray(JSON.parse('{\"r\":1,\"g\":0,\"b\":0}'));","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof BABYLON.Color3 || value instanceof BABYLON.Color4)) value = BABYLON.Color3.FromArray(value);","typeGuard":"const isBabylonColor = (v: unknown): v is BABYLON.Color3 | BABYLON.Color4 =>\n  v instanceof BABYLON.Color3 || v instanceof BABYLON.Color4;","tryCatchPattern":"try { return FromColor(value); } catch (e) { if (e.message === 'Invalid color type') { return Color3.FromArray(normalizeColor(value)); } throw e; }","preventionTips":["Reconstruct colors as Color3/Color4 instances when deserializing JSON","Never feed plain {r,g,b} literals or arrays where Color instances are expected","Avoid duplicating the Babylon core module, which breaks instanceof across realms"],"tags":["flow-graph","type-error","color"],"backgroundTag":"unsupported-input-type","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}