BabylonJS/Babylon.js · error
Cannot perform bitwise OR on ${a} and ${b}
Error message
Cannot perform bitwise OR on ${a} and ${b} What it means
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 ...'.
Source
Thrown at packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts:1255
/**
* Bitwise OR operation
*/
export class FlowGraphBitwiseOrBlock extends FlowGraphBinaryOperationBlock<FlowGraphBitwiseTypes, FlowGraphBitwiseTypes, FlowGraphBitwiseTypes> {
constructor(config?: IFlowGraphBitwiseBlockConfiguration) {
super(
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
(a, b) => {
if (typeof a === "boolean" && typeof b === "boolean") {
return a || b;
} else if (typeof a === "number" && typeof b === "number") {
return a | b;
} else if (typeof a === "object" && typeof b === "object") {
return new FlowGraphInteger(a.value | b.value);
} else {
throw new Error(`Cannot perform bitwise OR on ${a} and ${b}`);
}
},
FlowGraphBlockNames.BitwiseOr,
config
);
}
}
/**
* Bitwise XOR operation
*/
export class FlowGraphBitwiseXorBlock extends FlowGraphBinaryOperationBlock<FlowGraphBitwiseTypes, FlowGraphBitwiseTypes, FlowGraphBitwiseTypes> {
constructor(config?: IFlowGraphBlockConfiguration) {
super(
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
getRichTypeByFlowGraphType(config?.valueType || FlowGraphTypes.Integer),
(a, b) => {
View on GitHub (pinned to 0592b347b8)
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.
Example fix
// before: boolean OR number -> throws orBlock.a.connect(flagBlock.output); // boolean orBlock.b.connect(maskLiteral); // number // after: both numbers orBlock.a.connect(Number(flagBlock.output)); orBlock.b.connect(maskLiteral);
Defensive patterns
Strategy: type-guard
Validate before calling
// before BitwiseOr block runs
function bitwiseCompatible(a, b) {
const bool = (v) => typeof v === 'boolean';
const num = (v) => typeof v === 'number';
const int = (v) => typeof v === 'object' && v !== null && 'value' in v;
return (bool(a) && bool(b)) || (num(a) && num(b)) || (int(a) && int(b));
}
if (!bitwiseCompatible(orInputA, orInputB)) throw new TypeError('Bitwise OR needs two booleans, two numbers, or two FlowGraphIntegers'); Type guard
function isFlowGraphInteger(v): v is FlowGraphInteger {
return typeof v === 'object' && v !== null && 'value' in v && typeof (v as any).value === 'number';
}
function sameOperandKind(a: unknown, b: unknown): boolean {
return isFlowGraphInteger(a) === isFlowGraphInteger(b) && typeof a === typeof b;
} Try / catch
try {
result = orBlock.evaluate(context);
} catch (e) {
if (e.message.startsWith('Cannot perform bitwise OR')) {
result = toNum(a) | toNum(b); // normalize then retry
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot perform bitwise AND on ${a} and ${b}
- Cannot perform bitwise XOR on ${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/b324566b12d0b9c4.
Report an issue: GitHub.