emilk/egui · critical

Failed to create render state

Error message

Failed to create render state

What it means

WgpuTestRenderer::create_render_state builds an egui_wgpu RenderState (surface/adapter/device/pipeline) and unwraps it with .expect("Failed to create render state"). egui_wgpu's RenderState::create returns None/Err when no compatible GPU adapter, surface, or device can be initialized, so any kittest harness using the wgpu renderer fails hard at construction time when graphics initialization is impossible.

Source

Thrown at crates/egui_kittest/src/wgpu.rs:77

}

pub fn create_render_state(
    setup: WgpuSetup,
    options: egui_wgpu::RendererOptions,
) -> egui_wgpu::RenderState {
    // No display handle needed for headless testing — we don't present to a window.
    let instance = pollster::block_on(setup.new_instance());

    pollster::block_on(egui_wgpu::RenderState::create(
        &egui_wgpu::WgpuConfiguration {
            wgpu_setup: setup,
            ..Default::default()
        },
        &instance,
        None,
        options,
    ))
    .expect("Failed to create render state")
}

/// Utility to render snapshots from a [`crate::Harness`] using [`egui_wgpu`].
pub struct WgpuTestRenderer {
    render_state: RenderState,
}

impl Default for WgpuTestRenderer {
    fn default() -> Self {
        Self::new()
    }
}

impl WgpuTestRenderer {
    /// Create a new [`WgpuTestRenderer`] with the default setup.
    pub fn new() -> Self {
        Self {
            render_state: create_render_state(

View on GitHub (pinned to 441971a776)

Solutions

  1. Install GPU drivers or a software rasterizer (mesa vulkan-swrast / lavapipe) in the CI image and set VK_ICD_FILENAMES
  2. Set WGPU_BACKEND (e.g. gl or vulkan) to a backend the machine actually supports
  3. Fall back to the default (non-wgpu) kittest snapshot renderer when no GPU is available
  4. Replace the expect with graceful handling of the Option/Result and surface which stage (instance/adapter/device/surface) failed

Example fix

// before
let renderer = WgpuTestRenderer::create_render_state(options).expect("Failed to create render state");
// after
let renderer = match WgpuTestRenderer::create_render_state(options) {
    Some(r) => r,
    None => { eprintln!("wgpu unavailable, skipping GPU snapshot tests"); return; }
};
Defensive patterns

Strategy: fallback

Validate before calling

// Probe GPU availability before constructing the renderer:
let instance = wgpu::Instance::default();
let gpu_ok = instance.request_adapter(&wgpu::RequestAdapterOptions::default()).await.is_some();

Try / catch

// Degrade to the software snapshot path when wgpu can't init:
let renderer: Box<dyn SnapshotRenderer> =
    if let Some(r) = WgpuTestRenderer::create_render_state(options) {
        Box::new(r)
    } else {
        eprintln!("wgpu init failed; using default renderer");
        Box::new(DefaultSnapshotRenderer)
    };

Prevention

When it happens

Trigger: Calling WgpuTestRenderer::create_render_state (directly or via Harness options with the wgpu renderer) on a machine with no Vulkan/Metal/DX12-capable adapter, in a headless CI container without GPU access or software rendering (lavapipe/llvmpipe) installed, or with WGPU_BACKEND set to a backend the host cannot provide.

Common situations: GitHub Actions / Docker CI jobs without GPU drivers; Linux servers missing mesa/vulkan loaders; WGPU_BACKEND=metal on Linux or similar env mistakes; running inside VMs or sandboxes where device creation is blocked; requesting incompatible PowerPreference/limits in WgpuConfiguration.

Related errors


AI-assisted analysis of emilk/egui@441971a776 (2026-09-12). Data as JSON: /api/errors/20fc0506894be8b5. Report an issue: GitHub.