{"record":{"id":"cf73c85fd14702c9","repo":"BabylonJS/Babylon.js","slug":"cannot-normalize-value-a","errorCode":null,"errorMessage":"Cannot normalize value ${a}","messagePattern":"Cannot normalize value (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts","lineNumber":135,"sourceCode":"            case FlowGraphTypes.Vector4:\n            case FlowGraphTypes.Quaternion: {\n                // Normalization is only valid when the length is a positive finite number. For zero, NaN, or\n                // +Infinity length the operation is invalid: returning undefined makes the cached base report\n                // isValid = false and deliver a zero vector of the same type on `value`.\n                const length = (a as Vector3).length();\n                if (length === 0 || !Number.isFinite(length)) {\n                    if (this.config?.nanOnZeroLength) {\n                        // Legacy behavior preserved for consumers that opt into NaN output.\n                        const nanVector = a.normalizeToNew();\n                        nanVector.setAll(NaN);\n                        return nanVector;\n                    }\n                    return undefined;\n                }\n                return a.normalizeToNew();\n            }\n            default:\n                throw new Error(`Cannot normalize value ${a}`);\n        }\n    }\n\n    public override getClassName(): string {\n        return FlowGraphBlockNames.Normalize;\n    }\n}\n\n/**\n * Dot product block.\n */\nexport class FlowGraphDotBlock extends FlowGraphBinaryOperationBlock<FlowGraphVector, FlowGraphVector, number> {\n    constructor(config?: IFlowGraphBlockConfiguration) {\n        super(RichTypeAny, RichTypeAny, RichTypeNumber, (a, b) => this._polymorphicDot(a, b), FlowGraphBlockNames.Dot, config);\n    }\n\n    private _polymorphicDot(a: FlowGraphVector, b: FlowGraphVector) {\n        const className = _GetClassNameOf(a);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts#L117-L153","documentation":"The Normalize block's _polymorphicNormalize switches on the input's FlowGraphTypes and calls .normalizeToNew() only for supported vector types (Vector2/3/4, Quaternion). Values of any other type — scalars, booleans, matrices, undefined — fall to the default case and throw 'Cannot normalize value ...'. Normalization is only defined for vectors/quaternions in this API.","triggerScenarios":"Executing FlowGraphNormalizeBlock (_doOperation -> _polymorphicNormalize) when the input connection carries a non-vector value: a plain number, FlowGraphInteger, boolean, string, or Matrix.","commonSituations":"Wiring a scalar into Normalize expecting per-component division; an upstream block's output type changed from Vector3 to number after refactoring; serialized graph loaded with a default (undefined) input value.","solutions":["Connect a Vector2/Vector3/Vector4 or Quaternion to the Normalize block's input.","If you meant to divide a scalar by its magnitude conceptually, that is a no-op for scalars — remove the Normalize block and use the scalar directly (or abs for sign).","For matrices, extract row/column vectors first, or construct a vector block upstream before normalizing."],"exampleFix":"// before: number into Normalize -> throws\nnormalizeBlock.value.connect(scalarOutput); // number\n\n// after: vector input\nnormalizeBlock.value.connect(directionVectorBlock.output); // Vector3","handlingStrategy":"type-guard","validationCode":"// before Normalize block runs\nfunction validNormalizeInput(v) {\n  return v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3 ||\n         v instanceof BABYLON.Vector4 || v instanceof BABYLON.Quaternion;\n}\nif (!validNormalizeInput(normalizeInput)) throw new TypeError('Normalize input must be a vector or quaternion');","typeGuard":"function isVectorLike(v): v is BABYLON.Vector2 | BABYLON.Vector3 | BABYLON.Vector4 | BABYLON.Quaternion {\n  return v != null && typeof (v as any).normalizeToNew === 'function';\n}","tryCatchPattern":"try {\n  result = normalizeBlock.evaluate(context);\n} catch (e) {\n  if (e.message.startsWith('Cannot normalize value')) {\n    // fall back to identity for non-vectors or log graph wiring bug\n    result = normalizeInput;\n  } else { throw e; }\n}","preventionTips":["Normalize only direction-type vectors; scalars need no normalization.","Ensure inputs have non-zero length upstream to avoid zero-vector normalize issues.","Check port types in the editor before connecting; do not wire numeric outputs into vector ports."],"tags":["babylonjs","flow-graph","vector-math","type-mismatch"],"backgroundTag":"non-vector-input","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}