{"record":{"id":"662ae81f99205d99","repo":"BabylonJS/Babylon.js","slug":"cannot-compute-length-of-value-a","errorCode":null,"errorMessage":"Cannot compute length of value ${a}","messagePattern":"Cannot compute length of value (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts","lineNumber":58,"sourceCode":"\n/**\n * Vector length block.\n */\nexport class FlowGraphLengthBlock extends FlowGraphUnaryOperationBlock<FlowGraphVector, number> {\n    constructor(config?: IFlowGraphBlockConfiguration) {\n        super(RichTypeAny, RichTypeNumber, (a) => this._polymorphicLength(a), FlowGraphBlockNames.Length, config);\n    }\n\n    private _polymorphicLength(a: FlowGraphVector) {\n        const aClassName = _GetClassNameOf(a);\n        switch (aClassName) {\n            case FlowGraphTypes.Vector2:\n            case FlowGraphTypes.Vector3:\n            case FlowGraphTypes.Vector4:\n            case FlowGraphTypes.Quaternion:\n                return (a as Vector3).length();\n            default:\n                throw new Error(`Cannot compute length of value ${a}`);\n        }\n    }\n}\n\n/**\n * Configuration for normalized vector\n */\nexport interface IFlowGraphNormalizeBlockConfiguration extends IFlowGraphBlockConfiguration {\n    /**\n     * If true, the block will return NaN if the input vector has a length of 0.\n     * This is the expected behavior for glTF interactivity graphs.\n     */\n    nanOnZeroLength?: boolean;\n}\n\n/**\n * Vector normalize block.\n */","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts#L40-L76","documentation":"The vector Length block's _polymorphicLength computes .length() only for Vector2, Vector3, Vector4 and Quaternion inputs (via the FlowGraphTypes switch). Any other value — a plain number, boolean, string, or Matrix — hits the default case and throws 'Cannot compute length of value ...'. Scalars have no length in this API; use an absolute-value block instead.","triggerScenarios":"Connecting a scalar (number/FlowGraphInteger), boolean, or Matrix output into a FlowGraphLengthBlock input and executing the block during flow graph evaluation.","commonSituations":"Wanting the magnitude of a scalar (should use abs, not length); accidentally wiring a matrix output where a vector was expected; a graph where the upstream block type changed from Vector3 to number.","solutions":["Feed the block a Vector2/Vector3/Vector4 or Quaternion; for scalars, use an absolute-value math block instead of Length.","Insert the appropriate vector construction block (e.g. Vector3 from x,y,z) if the value must become a vector first.","Fix the mis-wired connection so a vector-typed output feeds the Length block."],"exampleFix":"// before: scalar into Length block -> throws\nlengthBlock.value.connect(numberOutput); // number\n\n// after: vector input (or use abs for scalars)\nlengthBlock.value.connect(positionVectorBlock.output); // Vector3","handlingStrategy":"type-guard","validationCode":"// before Length block runs\nconst LENGTH_TYPES = ['Vector2', 'Vector3', 'Vector4', 'Quaternion'];\nfunction validLengthInput(v) {\n  return v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3 ||\n         v instanceof BABYLON.Vector4 || v instanceof BABYLON.Quaternion;\n}\nif (!validLengthInput(lengthInput)) throw new TypeError('Length block 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).length === 'function';\n}","tryCatchPattern":"try {\n  result = lengthBlock.evaluate(context);\n} catch (e) {\n  if (e.message.startsWith('Cannot compute length of')) {\n    // scalar path: use abs instead\n    result = Math.abs(Number(lengthInput));\n  } else { throw e; }\n}","preventionTips":["Use the abs block for scalar magnitude; reserve Length for vectors/quaternions.","Check upstream output types when refactoring graphs — a Vector3 output replaced by a number will break Length.","Validate serialized graphs on load before first execution."],"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"}