BabylonJS/Babylon.js · error

FrameGraphClearTextureTask ${this.name}: targetTexture and d

Error message

FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.

What it means

FrameGraphClearTextureTask exists to clear either color target texture(s), a depth texture, or both. record() throws if both targetTexture and depthTexture are undefined, because there would be nothing to clear and no valid pass to record.

Source

Thrown at packages/dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts:78

    /**
     * Constructs a new clear task.
     * @param name The name of the task.
     * @param frameGraph The frame graph the task belongs to.
     */
    constructor(name: string, frameGraph: FrameGraph) {
        super(name, frameGraph);

        this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();
        this.outputDepthTexture = this._frameGraph.textureManager.createDanglingHandle();
    }

    public override getClassName(): string {
        return "FrameGraphClearTextureTask";
    }

    public record(skipCreationOfDisabledPasses = false): FrameGraphRenderPass {
        if (this.targetTexture === undefined && this.depthTexture === undefined) {
            throw new Error(`FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.`);
        }

        const textureManager = this._frameGraph.textureManager;
        const targetTextures = this.targetTexture !== undefined ? (Array.isArray(this.targetTexture) ? this.targetTexture : [this.targetTexture]) : undefined;

        if (this.targetTexture !== undefined) {
            textureManager.resolveDanglingHandle(this.outputTexture, targetTextures![0]);
        }
        if (this.depthTexture !== undefined) {
            textureManager.resolveDanglingHandle(this.outputDepthTexture, this.depthTexture);
        }
        if (this.targetTexture !== undefined && this.depthTexture !== undefined) {
            const targetDescription = textureManager.getTextureDescription(targetTextures![0]);
            const depthDescription = textureManager.getTextureDescription(this.depthTexture);

            if (targetDescription.size.width !== depthDescription.size.width || targetDescription.size.height !== depthDescription.size.height) {
                throw new Error(
                    `FrameGraphClearTextureTask ${this.name}: the depth texture (size: ${depthDescription.size.width}x${depthDescription.size.height}) and the target texture (size: ${targetDescription.size.width}x${targetDescription.size.height}) must have the same dimensions.`

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Assign task.targetTexture (single handle or array of handles) and/or task.depthTexture before build.
  2. If the intent was to clear the back buffer, set targetTexture to frameGraph.backBufferColorTexture.
  3. Remove the clear task entirely if no texture needs clearing.
  4. Validate at least one of the two fields is defined before frameGraph.build().

Example fix

// before
clearTask = new FrameGraphClearTextureTask('clear', frameGraph);
frameGraph.addTask(clearTask);
frameGraph.build(); // throws

// after
clearTask.targetTexture = frameGraph.backBufferColorTexture;
frameGraph.addTask(clearTask);
frameGraph.build();
Defensive patterns

Strategy: validation

Validate before calling

if (clearTask.targetTexture === undefined && clearTask.depthTexture === undefined) {
    throw new Error('ClearTextureTask needs a targetTexture or depthTexture');
}

Try / catch

try {
    frameGraph.build();
} catch (e) {
    if (String(e).includes("targetTexture and depthTexture can't both be undefined")) {
        console.error('Clear task has nothing to clear; assign a texture or remove the task');
    } else throw e;
}

Prevention

When it happens

Trigger: Adding a clear task and building the frame graph without assigning targetTexture or depthTexture; clearing a variable that was set to undefined after a refactor; conditional assignment logic that skipped both branches.

Common situations: Template/copy-pasted clear task never wired; a graph refactor removed the upstream texture the clear task targeted; mistakenly assuming the task clears the back buffer by default (it does not — you must pass the handle).

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/ae94d073ec261378. Report an issue: GitHub.