BabylonJS/Babylon.js · error · Error
Invalid channel input configuration
Error message
Invalid channel input configuration
What it means
MergeTexturesAsync decides per channel whether the input is a texture input, a constant input, or absent. This error is thrown when the channel object is present but matches neither recognized input shape — i.e. a malformed configuration object.
Source
Thrown at packages/dev/core/src/Materials/Textures/textureMerger.ts:128
if (channel.sourceChannel < 0 || channel.sourceChannel > 3) {
throw new Error("Source channel must be between 0 and 3 (R, G, B, A)");
}
// Find or add texture to inputs
let textureIndex = textureInputs.indexOf(channel.texture);
if (textureIndex === -1) {
textureIndex = textureInputs.length;
textureInputs.push(channel.texture);
}
textureInputMap[channelIndex] = textureIndex;
} else if (IsConstantInput(channel)) {
// Validate constant value
if (channel.value < 0 || channel.value > 1) {
throw new Error("Constant value must be between 0.0 and 1.0");
}
textureInputMap[channelIndex] = -1;
} else {
throw new Error("Invalid channel input configuration");
}
} else {
textureInputMap[channelIndex] = -1;
}
}
// Determine output size
let outputSize = config.outputSize;
if (!outputSize && textureInputs.length > 0) {
// Use the largest texture size
let maxSize = 0;
for (const texture of textureInputs) {
const size = texture.getSize();
const currentSize = Math.max(size.width, size.height);
if (currentSize > maxSize) {
maxSize = currentSize;
outputSize = size.width === size.height ? maxSize : size;
}View on GitHub (pinned to 0592b347b8)
Solutions
- Ensure each non-null channel is exactly { texture: BaseTexture, sourceChannel: 0-3 } or { value: 0-1 }.
- Log the channel object before calling to confirm the property names and that the intended field is not undefined.
- Use the documented helper (e.g. CreateMergedAnisotropyTexture) instead of building raw channel configs by hand.
Example fix
// before
{ tex: roughnessTexture, sourceChannel: 2 }
// after
{ texture: roughnessTexture, sourceChannel: 2 } Defensive patterns
Strategy: type-guard
Validate before calling
type TextureInput = { texture: BaseTexture; sourceChannel: number };
type ConstantInput = { value: number };
function isValidChannel(c: unknown): c is TextureInput | ConstantInput {
if (c == null || typeof c !== "object") return false;
const o = c as any;
return ("texture" in o && o.texture != null) || typeof o.value === "number";
} Type guard
function isTextureInput(c: unknown): c is { texture: BaseTexture; sourceChannel: number } {
return !!c && typeof c === "object" && "texture" in c && (c as any).texture != null;
} Try / catch
try {
const tex = await MergeTexturesAsync(channels, w, h, scene);
} catch (e) {
if (String(e.message).includes("Invalid channel input configuration")) {
console.error("Each channel must be {texture, sourceChannel} or {value}:", channels);
}
} Prevention
- Use discriminated union types for channel inputs and exhaustiveness checks.
- Validate deserialized channel configs before calling the merger.
- Prefer documented helpers like CreateMergedAnisotropyTexture over raw configs.
When it happens
Trigger: Passing a channel object to MergeTexturesAsync that is neither a texture input (has .texture) nor a constant input (has .value) — e.g. { texture: undefined, value: undefined }, a wrong property name, or an object created with a broken factory.
Common situations: Typos like { textureId } or { tex } instead of { texture }, passing a raw Texture instead of a channel descriptor, deserialized config that lost its shape, API version change in the merger input types.
Related errors
- Cannot compare ${a} and ${b}
- Cannot get NaN of ${a}
- Cannot get isInf of ${a}
- Cannot perform bitwise AND on ${a} and ${b}
- Cannot perform bitwise OR on ${a} and ${b}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/d7332bb3173b7991.
Report an issue: GitHub.