FyroxEngine/Fyrox · warning

Failed to create backbuffer depth-stencil

Error message

Failed to create backbuffer depth-stencil: {e}

What it means

The wgpu server lazily creates a depth-stencil texture matching the back buffer's size and caches it. If texture creation fails (e.g. the requested size is zero or exceeds device limits), the failure is logged with this message and the cache is set to None, meaning depth testing against the backbuffer will not work for that size.

Solutions

  1. Guard against zero-sized dimensions before creating/resizing the back buffer
  2. Clamp requested width/height to the device's max texture dimensions
  3. Check the underlying error {e} for the exact creation failure cause

Example fix

// before
let (w, h) = window.inner_size();
// after
let (w, h) = window.inner_size();
let (w, h) = (w.max(1), h.max(1));
Defensive patterns

Strategy: fallback

Validate before calling

let (w, h) = (size.width.max(1), size.height.max(1));
debug_assert!(w <= max_texture_dim && h <= max_texture_dim);

Prevention

When it happens

Trigger: Requesting a back buffer with a width/height whose depth-stencil texture creation fails — typically 0-sized or over device-limit dimensions (e.g. window minimized to 0x0 before depth buffer creation).

Common situations: Window resize events delivering 0 width/height; allocating framebuffers larger than max_texture_dimension; GPU memory exhaustion.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/b34962cf38320623. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-graphics-wgpu/src/server.rs:585

        let mut cache = self.backbuffer_depth_stencil.borrow_mut();
        let needs_recreate = match cache.as_ref() {
            Some((cw, ch, _)) => *cw != w || *ch != h,
            None => true,
        };
        if needs_recreate {
            if w > 0 && h > 0 {
                match self.create_2d_render_target(
                    "BackbufferDepthStencil",
                    fyrox_graphics::gpu_texture::PixelKind::D24S8,
                    w as usize,
                    h as usize,
                ) {
                    Ok(tex) => {
                        *cache = Some((w, h, tex));
                    }
                    Err(e) => {
                        Log::warn(format!("Failed to create backbuffer depth-stencil: {e}"));
                        *cache = None;
                    }
                }
            } else {
                *cache = None;
            }
        }
        let depth_attachment = cache
            .as_ref()
            .map(|(_, _, tex)| Attachment::depth_stencil(tex.clone()));
        GpuFrameBuffer(Rc::new(WgpuFrameBuffer::backbuffer(self, depth_attachment)))
    }
    fn create_query(&self) -> Result<GpuQuery, FrameworkError> {
        Ok(GpuQuery(Rc::new(WgpuQuery::new(self)?)))
    }
    fn create_shader(
        &self,
        name: String,

View on GitHub (pinned to 76c91aad8e)