{"record":{"id":"20fc0506894be8b5","repo":"emilk/egui","slug":"failed-to-create-render-state","errorCode":null,"errorMessage":"Failed to create render state","messagePattern":"Failed to create render state","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/egui_kittest/src/wgpu.rs","lineNumber":77,"sourceCode":"}\n\npub fn create_render_state(\n    setup: WgpuSetup,\n    options: egui_wgpu::RendererOptions,\n) -> egui_wgpu::RenderState {\n    // No display handle needed for headless testing — we don't present to a window.\n    let instance = pollster::block_on(setup.new_instance());\n\n    pollster::block_on(egui_wgpu::RenderState::create(\n        &egui_wgpu::WgpuConfiguration {\n            wgpu_setup: setup,\n            ..Default::default()\n        },\n        &instance,\n        None,\n        options,\n    ))\n    .expect(\"Failed to create render state\")\n}\n\n/// Utility to render snapshots from a [`crate::Harness`] using [`egui_wgpu`].\npub struct WgpuTestRenderer {\n    render_state: RenderState,\n}\n\nimpl Default for WgpuTestRenderer {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl WgpuTestRenderer {\n    /// Create a new [`WgpuTestRenderer`] with the default setup.\n    pub fn new() -> Self {\n        Self {\n            render_state: create_render_state(","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/egui_kittest/src/wgpu.rs#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install GPU drivers or a software rasterizer (mesa vulkan-swrast / lavapipe) in the CI image and set VK_ICD_FILENAMES","Set WGPU_BACKEND (e.g. gl or vulkan) to a backend the machine actually supports","Fall back to the default (non-wgpu) kittest snapshot renderer when no GPU is available","Replace the expect with graceful handling of the Option/Result and surface which stage (instance/adapter/device/surface) failed"],"exampleFix":"// before\nlet renderer = WgpuTestRenderer::create_render_state(options).expect(\"Failed to create render state\");\n// after\nlet renderer = match WgpuTestRenderer::create_render_state(options) {\n    Some(r) => r,\n    None => { eprintln!(\"wgpu unavailable, skipping GPU snapshot tests\"); return; }\n};","handlingStrategy":"fallback","validationCode":"// Probe GPU availability before constructing the renderer:\nlet instance = wgpu::Instance::default();\nlet gpu_ok = instance.request_adapter(&wgpu::RequestAdapterOptions::default()).await.is_some();","typeGuard":null,"tryCatchPattern":"// Degrade to the software snapshot path when wgpu can't init:\nlet renderer: Box<dyn SnapshotRenderer> =\n    if let Some(r) = WgpuTestRenderer::create_render_state(options) {\n        Box::new(r)\n    } else {\n        eprintln!(\"wgpu init failed; using default renderer\");\n        Box::new(DefaultSnapshotRenderer)\n    };","preventionTips":["Install mesa/lavapipe (software Vulkan) in CI images that run kittest wgpu snapshots","Set WGPU_BACKEND explicitly to a backend present on the target machine","Probe request_adapter once at startup and skip GPU-dependent tests when it returns None","Keep WgpuConfiguration (power preference, limits, backends) conservative for headless environments"],"tags":["wgpu","gpu","rendering","panic","testing"],"backgroundTag":"module-init-failed","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}