{"record":{"id":"70ac324aaac26d0e","repo":"BabylonJS/Babylon.js","slug":"cannot-perform-bitwise-and-on-a-and-b","errorCode":null,"errorMessage":"Cannot perform bitwise AND on ${a} and ${b}","messagePattern":"Cannot perform bitwise AND on (.+?) and (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts","lineNumber":1229,"sourceCode":"\r\n/**\r\n * Bitwise AND operation\r\n */\r\nexport class FlowGraphBitwiseAndBlock extends FlowGraphBinaryOperationBlock<FlowGraphBitwiseTypes, FlowGraphBitwiseTypes, FlowGraphBitwiseTypes> {\r\n    constructor(config?: IFlowGraphBitwiseBlockConfiguration) {\r\n        super(\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            (a, b) => {\r\n                if (typeof a === \"boolean\" && typeof b === \"boolean\") {\r\n                    return a && b;\r\n                } else if (typeof a === \"number\" && typeof b === \"number\") {\r\n                    return a & b;\r\n                } else if (typeof a === \"object\" && typeof b === \"object\") {\r\n                    return new FlowGraphInteger(a.value & b.value);\r\n                } else {\r\n                    throw new Error(`Cannot perform bitwise AND on ${a} and ${b}`);\r\n                }\r\n            },\r\n            FlowGraphBlockNames.BitwiseAnd,\r\n            config\r\n        );\r\n    }\r\n}\r\n\r\n/**\r\n * Bitwise OR operation\r\n */\r\nexport class FlowGraphBitwiseOrBlock extends FlowGraphBinaryOperationBlock<FlowGraphBitwiseTypes, FlowGraphBitwiseTypes, FlowGraphBitwiseTypes> {\r\n    constructor(config?: IFlowGraphBitwiseBlockConfiguration) {\r\n        super(\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),\r\n            (a, b) => {\r","sourceCodeStart":1211,"sourceCodeEnd":1247,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts#L1211-L1247","documentation":"The BitwiseAnd flow graph block supports three operand shapes: booleans (logical &&), plain numbers (a & b), or two FlowGraphInteger objects (integer value AND). Any other combination — e.g. one boolean and one number, a number and a FlowGraphInteger, a string, or a vector — falls through to the throw. Mixed representation operands are rejected rather than coerced.","triggerScenarios":"Executing FlowGraphBitwiseAndBlock with mismatched operand kinds: boolean+number, number+FlowGraphInteger, FlowGraphInteger+number, or any non-boolean/number/FlowGraphInteger value (string, vector) on either input.","commonSituations":"Connecting an integer-block output to one input and a plain number literal to the other; forgetting that both inputs must be the same representation; a serialized graph where one input's type changed.","solutions":["Make both inputs the same type: wrap both numbers in FlowGraphInteger, use two plain numbers, or two booleans.","Convert FlowGraphInteger to a number (intBlock.value.value / .value) or use a conversion block so both operands are plain numbers.","If a non-numeric value was wired by mistake, correct the connection in the flow graph editor."],"exampleFix":"// before: number AND FlowGraphInteger -> throws\nandBlock.a.connect(floatLiteral); // number\nandBlock.b.connect(intBlock.value); // FlowGraphInteger\n\n// after: both FlowGraphInteger\nandBlock.a.connect(new FlowGraphInteger(0b1100));\nandBlock.b.connect(intBlock.value);","handlingStrategy":"type-guard","validationCode":"// before BitwiseAnd block runs\nfunction bitwiseCompatible(a, b) {\n  const bool = (v) => typeof v === 'boolean';\n  const num = (v) => typeof v === 'number';\n  const int = (v) => typeof v === 'object' && v !== null && 'value' in v;\n  return (bool(a) && bool(b)) || (num(a) && num(b)) || (int(a) && int(b));\n}\nif (!bitwiseCompatible(andInputA, andInputB)) throw new TypeError('Bitwise AND needs two booleans, two numbers, or two FlowGraphIntegers');","typeGuard":"function isFlowGraphInteger(v): v is FlowGraphInteger {\n  return typeof v === 'object' && v !== null && 'value' in v && typeof (v as any).value === 'number';\n}\nfunction sameOperandKind(a: unknown, b: unknown): boolean {\n  return isFlowGraphInteger(a) === isFlowGraphInteger(b) && typeof a === typeof b;\n}","tryCatchPattern":"try {\n  result = andBlock.evaluate(context);\n} catch (e) {\n  if (e.message.startsWith('Cannot perform bitwise AND')) {\n    // normalize both to numbers and retry\n    result = toNum(a) & toNum(b);\n  } else { throw e; }\n}","preventionTips":["Standardize on FlowGraphInteger for all bitwise operations in a graph.","Do not mix boolean logic and bitwise masking in the same block instance.","Verify connection types in the editor; integer blocks and float blocks have distinct ports."],"tags":["babylonjs","flow-graph","bitwise","type-mismatch"],"backgroundTag":"bitwise-operand-type-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}