{"record":{"id":"9d57f5752122ee6a","repo":"BabylonJS/Babylon.js","slug":"framegraphcleartexturetask-this-name-the-depth","errorCode":null,"errorMessage":"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.","messagePattern":"FrameGraphClearTextureTask (.+?): the depth texture \\(size: (.+?)x(.+?)\\) and the target texture \\(size: (.+?)x(.+?)\\) must have the same dimensions\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts","lineNumber":95,"sourceCode":"        if (this.targetTexture === undefined && this.depthTexture === undefined) {\r\n            throw new Error(`FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.`);\r\n        }\r\n\r\n        const textureManager = this._frameGraph.textureManager;\r\n        const targetTextures = this.targetTexture !== undefined ? (Array.isArray(this.targetTexture) ? this.targetTexture : [this.targetTexture]) : undefined;\r\n\r\n        if (this.targetTexture !== undefined) {\r\n            textureManager.resolveDanglingHandle(this.outputTexture, targetTextures![0]);\r\n        }\r\n        if (this.depthTexture !== undefined) {\r\n            textureManager.resolveDanglingHandle(this.outputDepthTexture, this.depthTexture);\r\n        }\r\n        if (this.targetTexture !== undefined && this.depthTexture !== undefined) {\r\n            const targetDescription = textureManager.getTextureDescription(targetTextures![0]);\r\n            const depthDescription = textureManager.getTextureDescription(this.depthTexture);\r\n\r\n            if (targetDescription.size.width !== depthDescription.size.width || targetDescription.size.height !== depthDescription.size.height) {\r\n                throw new Error(\r\n                    `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.`\r\n                );\r\n            }\r\n\r\n            const textureSamples = targetDescription.options.samples || 1;\r\n            const depthSamples = depthDescription.options.samples || 1;\r\n\r\n            if (textureSamples !== depthSamples && textureSamples !== 0 && depthSamples !== 0) {\r\n                throw new Error(\r\n                    `FrameGraphClearTextureTask ${this.name}: the depth texture (${depthSamples} samples) and the target texture (${textureSamples} samples) must have the same number of samples.`\r\n                );\r\n            }\r\n        }\r\n\r\n        const attachments = this._frameGraph.engine.buildTextureLayout(\r\n            targetTextures ? Array(targetTextures.length).fill(true) : [],\r\n            this.targetTexture === backbufferColorTextureHandle && !this._frameGraph.textureManager.backBufferTextureOverriden\r\n        );\r","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts#L77-L113","documentation":"When FrameGraphClearTextureTask is given both a target texture and a depth texture, record() checks that their dimensions match, since the clear pass clears both attachments in one render pass whose viewport size must be consistent. Mismatched sizes throw with both sizes in the message.","triggerScenarios":"Assigning targetTexture and depthTexture whose getTextureDescription sizes differ (e.g. color 1920x1080 vs depth 1024x1024), detected in record().","commonSituations":"Depth texture sized for a different render target; resize handling updated the color target but not the depth; hard-coded sizes copied from another task.","solutions":["Recreate the depth texture at the same width/height as the target texture.","Derive the depth size from the target description before creating it.","If sizes must differ, use two separate clear tasks (one for color, one for depth) instead of one.","Synchronize both textures in your resize logic."],"exampleFix":"// before\nclearTask.targetTexture = colorTexture;   // 1920x1080\nclearTask.depthTexture = depthTexture;    // 1024x1024\n\n// after\nconst desc = frameGraph.textureManager.getTextureDescription(colorHandle);\nconst depthTexture = frameGraph.createDepthStencilTexture('depth', { size: { width: desc.size.width, height: desc.size.height } });\nclearTask.targetTexture = colorTexture;\nclearTask.depthTexture = depthTexture;","handlingStrategy":"validation","validationCode":"if (clearTask.targetTexture !== undefined && clearTask.depthTexture !== undefined) {\n    const t = frameGraph.textureManager.getTextureDescription(Array.isArray(clearTask.targetTexture) ? clearTask.targetTexture[0] : clearTask.targetTexture);\n    const d = frameGraph.textureManager.getTextureDescription(clearTask.depthTexture);\n    if (t.size.width !== d.size.width || t.size.height !== d.size.height) throw new Error('Clear pass depth/target size mismatch');\n}","typeGuard":null,"tryCatchPattern":"try {\n    frameGraph.build();\n} catch (e) {\n    if (String(e).includes('must have the same dimensions')) {\n        // split into separate color/depth clear tasks or recreate depth at target size\n    } else throw e;\n}","preventionTips":["Create the depth texture for a clear task from the target texture's description.","Resize color and depth attachments in the same handler.","Prefer separate clear tasks when color and depth have different lifecycles."],"tags":["babylonjs","frame-graph","clear-pass","size-mismatch","depth-texture"],"backgroundTag":"render-target-size-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}