BabylonJS/Babylon.js · error
Cannot get NaN of ${a}
Error message
Cannot get NaN of ${a} What it means
The IsNaN flow graph block calls _polymorphicIsNan, which uses isNumeric(a, true) — a variant that accepts numbers and FlowGraphInteger values only (the second argument is not the boolean-tolerant mode here). If the input is a boolean, string, vector, or other FlowGraphTypes value, the block throws instead of returning a result. NaN checks only make sense for numeric inputs, so non-numeric input is treated as an authoring error.
Source
Thrown at packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts:858
private _polymorphicGreaterThanOrEqual(a: FlowGraphNumber, b: FlowGraphNumber) {
return ComparisonOperators(a, b, (a, b) => a >= b);
}
}
/**
* Is NaN block.
*/
export class FlowGraphIsNanBlock extends FlowGraphUnaryOperationBlock<FlowGraphNumber, boolean> {
constructor(config?: IFlowGraphBlockConfiguration) {
super(RichTypeAny, RichTypeBoolean, (a) => this._polymorphicIsNan(a), FlowGraphBlockNames.IsNaN, config);
}
private _polymorphicIsNan(a: FlowGraphNumber) {
if (isNumeric(a, true)) {
return isNaN(getNumericValue(a));
} else {
throw new Error(`Cannot get NaN of ${a}`);
}
}
}
/**
* Is Inf block.
*/
export class FlowGraphIsInfinityBlock extends FlowGraphUnaryOperationBlock<FlowGraphNumber, boolean> {
constructor(config?: IFlowGraphBlockConfiguration) {
super(RichTypeAny, RichTypeBoolean, (a) => this._polymorphicIsInf(a), FlowGraphBlockNames.IsInfinity, config);
}
private _polymorphicIsInf(a: FlowGraphNumber) {
if (isNumeric(a)) {
return !isFinite(getNumericValue(a));
} else {
throw new Error(`Cannot get isInf of ${a}`);
}
View on GitHub (pinned to 0592b347b8)
Solutions
- Feed the IsNaN block a numeric input only; if the value may be missing, provide a numeric default (e.g. 0) upstream before the block.
- Replace the IsNaN block with a type/value check block appropriate to the actual data type being tested.
- Inspect the connection in the flow graph editor and remove the wrong-typed wire feeding the block.
Example fix
// before: boolean into IsNaN isNaNBlock.value.connect(logicBlock.output); // throws // after: numeric input isNaNBlock.value.connect(divideBlock.output); // number input is valid
Defensive patterns
Strategy: validation
Validate before calling
// before IsNaN block runs
function validIsNanInput(v) {
return typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v);
}
if (!validIsNanInput(isNanInput)) throw new TypeError('IsNaN input must be a number or FlowGraphInteger'); Type guard
function isNumericValue(v): v is number | FlowGraphInteger {
return typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v);
} Try / catch
try {
result = isNanBlock.evaluate(context);
} catch (e) {
if (e.message.startsWith('Cannot get NaN of')) {
result = false; // or handle as 'input was not numeric'
} else { throw e; }
} Prevention
- Give numeric inputs explicit numeric defaults so an 'empty' connection never carries a wrong type.
- Use IsNaN only downstream of arithmetic blocks that provably output numbers.
- Validate serialized graphs after load: check connection source types match target port expectations.
When it happens
Trigger: Connecting a non-numeric connection (boolean, string, Vector2/3/4, Quaternion, FlowGraphInteger is OK) into the IsNaN block's input and executing the block.
Common situations: Using IsNaN to test whether an optional/undefined input 'is empty' — the wiring carries a wrong-typed default value; passing a boolean from a logic block into IsNaN; graph serialization assigning a string to the input.
Related errors
- Cannot compare ${a} and ${b}
- Cannot get isInf of ${a}
- Cannot perform bitwise AND on ${a} and ${b}
- Cannot perform bitwise OR on ${a} and ${b}
- Cannot perform bitwise XOR on ${a} and ${b}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/7d0b88d5071442e9.
Report an issue: GitHub.