BabylonJS/Babylon.js · error · Error
Cannot normalize value ${a}
Error message
Cannot normalize value ${a} What it means
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.
Source
Thrown at packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts:135
case FlowGraphTypes.Vector4:
case FlowGraphTypes.Quaternion: {
// Normalization is only valid when the length is a positive finite number. For zero, NaN, or
// +Infinity length the operation is invalid: returning undefined makes the cached base report
// isValid = false and deliver a zero vector of the same type on `value`.
const length = (a as Vector3).length();
if (length === 0 || !Number.isFinite(length)) {
if (this.config?.nanOnZeroLength) {
// Legacy behavior preserved for consumers that opt into NaN output.
const nanVector = a.normalizeToNew();
nanVector.setAll(NaN);
return nanVector;
}
return undefined;
}
return a.normalizeToNew();
}
default:
throw new Error(`Cannot normalize value ${a}`);
}
}
public override getClassName(): string {
return FlowGraphBlockNames.Normalize;
}
}
/**
* Dot product block.
*/
export class FlowGraphDotBlock extends FlowGraphBinaryOperationBlock<FlowGraphVector, FlowGraphVector, number> {
constructor(config?: IFlowGraphBlockConfiguration) {
super(RichTypeAny, RichTypeAny, RichTypeNumber, (a, b) => this._polymorphicDot(a, b), FlowGraphBlockNames.Dot, config);
}
private _polymorphicDot(a: FlowGraphVector, b: FlowGraphVector) {
const className = _GetClassNameOf(a);View on GitHub (pinned to 0592b347b8)
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.
Example fix
// before: number into Normalize -> throws normalizeBlock.value.connect(scalarOutput); // number // after: vector input normalizeBlock.value.connect(directionVectorBlock.output); // Vector3
Defensive patterns
Strategy: type-guard
Validate before calling
// before Normalize block runs
function validNormalizeInput(v) {
return v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3 ||
v instanceof BABYLON.Vector4 || v instanceof BABYLON.Quaternion;
}
if (!validNormalizeInput(normalizeInput)) throw new TypeError('Normalize input must be a vector or quaternion'); Type guard
function isVectorLike(v): v is BABYLON.Vector2 | BABYLON.Vector3 | BABYLON.Vector4 | BABYLON.Quaternion {
return v != null && typeof (v as any).normalizeToNew === 'function';
} Try / catch
try {
result = normalizeBlock.evaluate(context);
} catch (e) {
if (e.message.startsWith('Cannot normalize value')) {
// fall back to identity for non-vectors or log graph wiring bug
result = normalizeInput;
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: Executing FlowGraphNormalizeBlock (_doOperation -> _polymorphicNormalize) when the input connection carries a non-vector value: a plain number, FlowGraphInteger, boolean, string, or Matrix.
Common situations: 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.
Related errors
- Cannot compute length of value ${a}
- Cannot get dot product of ${a} and ${b}
- Cannot compare ${a} and ${b}
- Cannot get NaN of ${a}
- Cannot get isInf of ${a}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/cf73c85fd14702c9.
Report an issue: GitHub.