BabylonJS/Babylon.js · error · Error

FrameGraphHighlightLayerTask "${this.name}": objectRendererT

Error message

FrameGraphHighlightLayerTask "${this.name}": objectRendererTask depthTexture must have a stencil aspect

What it means

FrameGraphHighlightLayerTask requires the objectRendererTask's depthTexture input to be created with a texture format that includes a stencil aspect (e.g. DEPTH24STENCIL8 or DEPTH32FLOAT_STENCIL8). During record(), the task inspects the depth texture's creation options and throws if the first format lacks stencil, because the highlight layer renders object IDs into a stencil-based mask. This guards against silent visual corruption when the stencil buffer is missing.

Source

Thrown at packages/dev/core/src/FrameGraph/Tasks/Layers/highlightLayerTask.ts:49

            1,
            alphaBlendingMode === Constants.ALPHA_COMBINE ? FrameGraphBaseLayerBlurType.Glow : FrameGraphBaseLayerBlurType.Standard,
            true,
            true
        );
    }

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

    public override record() {
        if (!this.objectRendererTask.depthTexture) {
            throw new Error(`FrameGraphHighlightLayerTask "${this.name}": objectRendererTask must have a depthTexture input`);
        }

        const depthTextureCreationOptions = this._frameGraph.textureManager.getTextureCreationOptions(this.objectRendererTask.depthTexture);
        if (!depthTextureCreationOptions.options.formats || !HasStencilAspect(depthTextureCreationOptions.options.formats[0])) {
            throw new Error(`FrameGraphHighlightLayerTask "${this.name}": objectRendererTask depthTexture must have a stencil aspect`);
        }

        super.record();

        this.layer._mainObjectRendererRenderPassId = this.objectRendererTask.objectRenderer.renderPassId;
    }
}

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Recreate the depth texture used by objectRendererTask with a stencil-bearing format such as Constants.TEXTUREFORMAT_DEPTH24STENCIL8 (or DEPTH32FLOAT_STENCIL8) as the first entry in options.formats.
  2. Verify via frameGraph.textureManager.getTextureCreationOptions(depthTexture).options.formats[0] and HasStencilAspect() before recording the task.
  3. Ensure the depthTexture handle actually points to the intended texture (not an intermediate depth target created elsewhere with a depth-only format).

Example fix

// before
const depthTex = frameGraph.createTexture({ size: { width, height }, options: { formats: [Constants.TEXTUREFORMAT_DEPTH32FLOAT] } });
objectRendererTask.depthTexture = depthTex;
// after
const depthTex = frameGraph.createTexture({ size: { width, height }, options: { formats: [Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8] } });
objectRendererTask.depthTexture = depthTex;
Defensive patterns

Strategy: validation

Validate before calling

const opts = frameGraph.textureManager.getTextureCreationOptions(task.objectRendererTask.depthTexture);
if (!opts.options.formats || !HasStencilAspect(opts.options.formats[0])) {
  throw new Error("highlightLayer depth texture must use a stencil format");
}

Type guard

function hasStencilDepth(tex: ReturnType<typeof frameGraph.createTexture> | undefined): boolean {
  if (!tex) return false;
  const opts = frameGraph.textureManager.getTextureCreationOptions(tex);
  return !!opts.options.formats && HasStencilAspect(opts.options.formats[0]);
}

Try / catch

try {
  highlightLayerTask.record();
} catch (e) {
  if (String(e).includes("stencil aspect")) {
    // recreate depth texture with DEPTH24STENCIL8 / DEPTH32FLOAT_STENCIL8 and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling highlightLayerTask.record() when objectRendererTask.depthTexture exists but was created with formats whose first entry lacks a stencil aspect (e.g. DEPTH16, DEPTH24, DEPTH32FLOAT without stencil).

Common situations: Creating the depth texture for the object renderer task with a plain depth-only format, or letting texture creation options omit/reorder formats so index 0 is stencil-less; copy-pasted task setup code from samples using non-stencil depth formats.

Related errors


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