{"record":{"id":"e356862035d0b5bc","repo":"bevyengine/bevy","slug":"can-t-create-depth-attachment-texture-format-is-n","errorCode":null,"errorMessage":"Can't create depth attachment. Texture format is not a depth-stencil format.","messagePattern":"Can't create depth attachment\\. Texture format is not a depth-stencil format\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/texture/texture_attachment.rs","lineNumber":188,"sourceCode":"            })\n        };\n\n        match texture.texture.format().channels() {\n            wgpu_types::TextureChannel::DEPTH_STENCIL => DepthStencilViews::DepthStencil {\n                combined_view: texture\n                    .texture\n                    .create_view(&TextureViewDescriptor::default()),\n                depth_view: depth_view(),\n                stencil_view: stencil_view(),\n            },\n            wgpu_types::TextureChannel::DEPTH => DepthStencilViews::DepthOnly {\n                depth_view: depth_view(),\n            },\n            wgpu_types::TextureChannel::STENCIL => DepthStencilViews::StencilOnly {\n                stencil_view: stencil_view(),\n            },\n            _ => {\n                panic!(\n                    \"Can't create depth attachment. Texture format is not a depth-stencil format.\"\n                )\n            }\n        }\n    }\n}\n\n/// A wrapper for a [`CachedTexture`] that is used as a depth [`RenderPassDepthStencilAttachment`].\n#[derive(Clone)]\npub struct DepthStencilAttachment {\n    pub texture: CachedTexture,\n    pub previous_frame_texture: Option<CachedTexture>,\n    depth_stencil_view_attachment: DepthStencilViewAttachment,\n    pub previous_frame_depth_stencil_views: Option<DepthStencilViews>,\n}\n\nimpl DepthStencilAttachment {\n    pub fn depth_stencil_views(&self) -> &DepthStencilViews {","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/texture/texture_attachment.rs#L170-L206","documentation":"When building the DepthStencilViews for a depth attachment, the code matches the texture format's channel: DEPTH_STENCIL, DEPTH, and STENCIL map to view sets, and every other format — i.e. any color format — panics with 'not a depth-stencil format'. Depth attachments must use actual depth/stencil formats such as Depth32Float or Depth24PlusStencil8.","triggerScenarios":"Constructing a DepthStencilAttachment (or configuring a camera/extracted view's depth texture) over a CachedTexture whose format is a color format like Bgra8Unorm — for example copying a render-target format into the depth configuration or resolving the wrong texture.","commonSituations":"Custom render graphs where the depth target is allocated with the same format as the color target; switching a post-processing target to depth usage without changing format; refactors that mix up color and depth CachedTextures.","solutions":["Allocate the depth texture with a depth or depth-stencil format (Depth32Float, Depth16Unorm, Depth24Plus, Depth24PlusStencil8)","Check format.has_depth_aspect() / has_stencil_aspect() before building the attachment and fail with a clear error instead","Audit render-graph node definitions to ensure the depth target is not reusing a color format string/constant"],"exampleFix":"// before\nlet depth_texture = texture_cache.get(&depth_image_descriptor, /* format */ TextureFormat::Bgra8Unorm);\nlet attachment = DepthStencilAttachment::new(depth_texture);\n\n// after\nlet depth_texture = texture_cache.get(\n    &depth_image_descriptor,\n    TextureFormat::Depth32Float,\n);\nlet attachment = DepthStencilAttachment::new(depth_texture);","handlingStrategy":"type-guard","validationCode":"// Before building the attachment:\nif !format.has_depth_aspect() && !format.has_stencil_aspect() {\n    return Err(format!(\"{format:?} is not a depth-stencil format\"));\n}","typeGuard":"fn is_depth_stencil_format(f: wgpu::TextureFormat) -> bool {\n    f.has_depth_aspect() || f.has_stencil_aspect()\n}","tryCatchPattern":null,"preventionTips":["Allocate depth textures only with Depth*/Stencil* formats (Depth32Float, Depth24PlusStencil8, ...)","Assert the format has a depth aspect in debug builds when constructing depth attachments","Keep color- and depth-format constants separated in render-graph node definitions"],"tags":["bevy","depth-buffer","texture-format","render-graph","panic"],"backgroundTag":"invalid-texture-format","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}