{"record":{"id":"e1f25830440a90a6","repo":"FyroxEngine/Fyrox","slug":"attempt-to-use-color-attachment-as-depth-stencil","errorCode":null,"errorMessage":"Attempt to use color attachment as depth/stencil!","messagePattern":"Attempt to use color attachment as depth/stencil!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-graphics-gl/src/framebuffer.rs","lineNumber":112,"sourceCode":"        }\n    }\n}\n\nimpl GlFrameBuffer {\n    pub fn new(\n        server: &GlGraphicsServer,\n        depth_attachment: Option<Attachment>,\n        color_attachments: Vec<Attachment>,\n    ) -> Result<Self, FrameworkError> {\n        unsafe {\n            let fbo = server.gl.create_framebuffer()?;\n\n            server.set_framebuffer(FrameBufferBindingPoint::ReadWrite, Some(fbo));\n\n            if let Some(depth_attachment) = depth_attachment.as_ref() {\n                let depth_attachment_kind = match depth_attachment.kind {\n                    AttachmentKind::Color => {\n                        panic!(\"Attempt to use color attachment as depth/stencil!\")\n                    }\n                    AttachmentKind::DepthStencil => glow::DEPTH_STENCIL_ATTACHMENT,\n                    AttachmentKind::Depth => glow::DEPTH_ATTACHMENT,\n                };\n                let texture = depth_attachment\n                    .texture\n                    .as_any()\n                    .downcast_ref::<GlTexture>()\n                    .unwrap();\n                set_attachment(\n                    server,\n                    depth_attachment_kind,\n                    texture,\n                    depth_attachment.level() as i32,\n                    depth_attachment.cube_map_face(),\n                );\n            }\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-graphics-gl/src/framebuffer.rs#L94-L130","documentation":"When creating a framebuffer in the OpenGL backend, the depth/stencil attachment slot was given a texture that is a color attachment. Only depth or depth/stencil textures can be bound to the DEPTH_STENCIL/DEPTH attachment point, so the library panics to prevent an invalid GL framebuffer.","triggerScenarios":"Calling FrameBuffer::new (fyrox-graphics-gl) passing a texture created with a color pixel kind/format as the depth_attachment while supplying another (or no) color attachment.","commonSituations":"Building a render target manually and reusing a color texture (e.g. RGBA8) as the depth buffer; forgetting to create a separate DEPTH32F/D24S8 texture for the depth slot; copy-pasted framebuffer setup code from a color-target example.","solutions":["Create the depth texture with a depth or depth/stencil pixel kind (e.g. D32, D24S8) and pass that as depth_attachment","Pass None for depth_attachment if no depth testing is needed","Check texture.kind() / AttachmentKind before constructing the framebuffer and fail fast with a clear message"],"exampleFix":"// before\nlet color = RenderTarget::texture(Texture::new(ctx, TextureDescriptor { kind: TextureKind::D2{..}, pixel_kind: PixelKind::RGBA8, ..}));\nlet fb = FrameBuffer::new(ctx, Some(&color), Some(&color));\n// after\nlet depth = Texture::new(ctx, TextureDescriptor { pixel_kind: PixelKind::D24S8, .. });\nlet fb = FrameBuffer::new(ctx, Some(&color), Some(&depth));","handlingStrategy":"validation","validationCode":"assert!(matches!(depth_tex.pixel_kind(), PixelKind::D32 | PixelKind::D24 | PixelKind::D24S8), \"depth attachment must be a depth/stencil texture\");","typeGuard":"fn is_depth_attachment(a: &Attachment) -> bool { !matches!(a.kind, AttachmentKind::Color) }","tryCatchPattern":null,"preventionTips":["Always create depth textures with D32/D24S8 pixel kinds","Never reuse a color target texture as depth attachment","Wrap framebuffer creation in a helper that validates attachment kinds"],"tags":["opengl","framebuffer","graphics","panic"],"backgroundTag":"invalid-argument-value","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}