BabylonJS/Babylon.js · error
Cannot perform bitwise AND on ${a} and ${b}
Error message
Cannot perform bitwise AND on ${a} and ${b} What it means
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.
Source
Thrown at packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts:1229
/**
* Bitwise AND operation
*/
export class FlowGraphBitwiseAndBlock 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 AND on ${a} and ${b}`);
}
},
FlowGraphBlockNames.BitwiseAnd,
config
);
}
}
/**
* 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) => {
View on GitHub (pinned to 0592b347b8)
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.
Example fix
// before: number AND FlowGraphInteger -> throws andBlock.a.connect(floatLiteral); // number andBlock.b.connect(intBlock.value); // FlowGraphInteger // after: both FlowGraphInteger andBlock.a.connect(new FlowGraphInteger(0b1100)); andBlock.b.connect(intBlock.value);
Defensive patterns
Strategy: type-guard
Validate before calling
// before BitwiseAnd 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(andInputA, andInputB)) throw new TypeError('Bitwise AND 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 = andBlock.evaluate(context);
} catch (e) {
if (e.message.startsWith('Cannot perform bitwise AND')) {
// normalize both to numbers and retry
result = toNum(a) & toNum(b);
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: Executing FlowGraphBitwiseAndBlock with mismatched operand kinds: boolean+number, number+FlowGraphInteger, FlowGraphInteger+number, or any non-boolean/number/FlowGraphInteger value (string, vector) on either input.
Common situations: 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.
Related errors
- Cannot perform bitwise OR 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/70ac324aaac26d0e.
Report an issue: GitHub.