{"record":{"id":"a89ad23f6345e119","repo":"mrdoob/three.js","slug":"three-webgltextures-rendertarget-depthtexture-mus","errorCode":null,"errorMessage":"THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.","messagePattern":"THREE\\.WebGLTextures: renderTarget\\.depthTexture must be an instance of THREE\\.DepthTexture\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderers/webgl/WebGLTextures.js","lineNumber":1763,"sourceCode":"\n\t\t\t}\n\n\t\t}\n\n\t\t_gl.bindRenderbuffer( _gl.RENDERBUFFER, null );\n\n\t}\n\n\t// Setup resources for a Depth Texture for a FBO (needs an extension)\n\tfunction setupDepthTexture( framebuffer, renderTarget, cubeFace ) {\n\n\t\tconst isCube = ( renderTarget.isWebGLCubeRenderTarget === true );\n\n\t\tstate.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );\n\n\t\tif ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {\n\n\t\t\tthrow new Error( 'THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.' );\n\n\t\t}\n\n\t\tconst textureProperties = properties.get( renderTarget.depthTexture );\n\t\ttextureProperties.__renderTarget = renderTarget;\n\n\t\t// upload an empty depth texture with framebuffer size\n\t\tif ( ! textureProperties.__webglTexture ||\n\t\t\t\trenderTarget.depthTexture.image.width !== renderTarget.width ||\n\t\t\t\trenderTarget.depthTexture.image.height !== renderTarget.height ) {\n\n\t\t\trenderTarget.depthTexture.image.width = renderTarget.width;\n\t\t\trenderTarget.depthTexture.image.height = renderTarget.height;\n\t\t\trenderTarget.depthTexture.needsUpdate = true;\n\n\t\t}\n\n\t\tif ( isCube ) {","sourceCodeStart":1745,"sourceCodeEnd":1781,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/renderers/webgl/WebGLTextures.js#L1745-L1781","documentation":"Thrown by WebGLTextures.setupDepthTexture() when a render target has a depthTexture set but it is not an instance of THREE.DepthTexture (i.e. its `isDepthTexture` flag is false). WebGL FBO depth attachments require a proper DepthTexture object so the renderer can configure the depth format, attachment, and image dimensions correctly.","triggerScenarios":"Assigning `renderTarget.depthTexture = someTexture` where someTexture is a regular Texture, DataTexture, or any non-DepthTexture. Reusing a render target whose depthTexture was overwritten with a generic texture.","commonSituations":"Copying a depth-texture example but constructing a plain Texture instead of DepthTexture. Sharing a depth attachment across render targets with the wrong type. Migrating code that previously used a non-typed depth placeholder.","solutions":["Use `new THREE.DepthTexture(width, height, type)` and assign that to renderTarget.depthTexture.","If sharing depth across targets, share the same DepthTexture instance, not a generic texture.","Verify with `rt.depthTexture.isDepthTexture === true` before rendering.","Leave depthTexture null if you only need a depth buffer (the renderer will allocate a renderbuffer)."],"exampleFix":"// before\nrt.depthTexture = new THREE.DataTexture(data, w, h); // not a DepthTexture -> throws\n\n// after\nrt.depthTexture = new THREE.DepthTexture(w, h, THREE.UnsignedIntType);","handlingStrategy":"type-guard","validationCode":"function attachDepthTexture(rt, w, h, type = THREE.UnsignedIntType) {\n  const dt = new THREE.DepthTexture(w, h, type);\n  rt.depthTexture = dt;\n  if (!dt.isDepthTexture) throw new Error('DepthTexture construction failed');\n}","typeGuard":"function isDepthTexture(v) {\n  return !!v && v.isDepthTexture === true;\n}","tryCatchPattern":null,"preventionTips":["Always construct depth attachments with `new THREE.DepthTexture(...)`; never reuse a generic Texture.","Assert `rt.depthTexture.isDepthTexture === true` before rendering in debug builds.","Leave depthTexture null if you only need a depth buffer (renderer allocates a renderbuffer)."],"tags":["webgl","render-target","depth-texture","fbo","type-error"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}