{"record":{"id":"b324566b12d0b9c4","repo":"BabylonJS/Babylon.js","slug":"cannot-perform-bitwise-or-on-a-and-b","errorCode":null,"errorMessage":"Cannot perform bitwise OR on ${a} and ${b}","messagePattern":"Cannot perform bitwise OR on (.+?) and (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts","lineNumber":1255,"sourceCode":"\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\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 OR on ${a} and ${b}`);\r\n                }\r\n            },\r\n            FlowGraphBlockNames.BitwiseOr,\r\n            config\r\n        );\r\n    }\r\n}\r\n\r\n/**\r\n * Bitwise XOR operation\r\n */\r\nexport class FlowGraphBitwiseXorBlock extends FlowGraphBinaryOperationBlock<FlowGraphBitwiseTypes, FlowGraphBitwiseTypes, FlowGraphBitwiseTypes> {\r\n    constructor(config?: IFlowGraphBlockConfiguration) {\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":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts#L1237-L1273","documentation":"The BitwiseOr flow graph block accepts only: two booleans (logical ||), two plain numbers (a | b), or two FlowGraphInteger objects (a.value | b.value wrapped back into FlowGraphInteger). Anything else — mixed boolean/number, number/FlowGraphInteger, strings, vectors — throws 'Cannot perform bitwise OR on ...'.","triggerScenarios":"Executing FlowGraphBitwiseOrBlock where the two inputs are not the same supported kind: boolean with number, number with FlowGraphInteger, or any other value type on either port.","commonSituations":"Mixing an integer-producing block output with a numeric literal; using the block as a logic gate but feeding one boolean and one numeric flag; graph refactor changing an upstream block's output type.","solutions":["Unify operand types: both booleans for logic, both numbers or both FlowGraphInteger for bit operations.","Insert a conversion (integer-to-number) block or wrap the number in new FlowGraphInteger(n) before connecting.","Re-wire the incorrect input port in the flow graph editor to a matching-typed output."],"exampleFix":"// before: boolean OR number -> throws\norBlock.a.connect(flagBlock.output); // boolean\norBlock.b.connect(maskLiteral); // number\n\n// after: both numbers\norBlock.a.connect(Number(flagBlock.output));\norBlock.b.connect(maskLiteral);","handlingStrategy":"type-guard","validationCode":"// before BitwiseOr 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(orInputA, orInputB)) throw new TypeError('Bitwise OR 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 = orBlock.evaluate(context);\n} catch (e) {\n  if (e.message.startsWith('Cannot perform bitwise OR')) {\n    result = toNum(a) | toNum(b); // normalize then retry\n  } else { throw e; }\n}","preventionTips":["Use dedicated logic blocks (FlowGraphBooleanOr) for boolean OR instead of the bitwise block.","Keep masks as FlowGraphInteger throughout so both OR inputs share a type.","Re-validate graph connections after engine upgrades that may change block output types."],"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"}