{"record":{"id":"58aa3e1ef4dd089b","repo":"zed-industries/zed","slug":"failed-to-get-window-handle-e","errorCode":null,"errorMessage":"Failed to get window handle: {e}","messagePattern":"Failed to get window handle: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_wgpu/src/wgpu_renderer.rs","lineNumber":270,"sourceCode":"    /// multiple windows. The first window to create a renderer will initialize the\n    /// context; subsequent windows will share it.\n    ///\n    /// # Safety\n    /// The caller must ensure that the window handle remains valid for the lifetime\n    /// of the returned renderer.\n    #[cfg(not(target_family = \"wasm\"))]\n    pub fn new<W>(\n        gpu_context: GpuContext,\n        window: &W,\n        config: WgpuSurfaceConfig,\n        compositor_gpu: Option<CompositorGpuHint>,\n    ) -> anyhow::Result<Self>\n    where\n        W: HasWindowHandle + HasDisplayHandle + std::fmt::Debug + Send + Sync + Clone + 'static,\n    {\n        let window_handle = window\n            .window_handle()\n            .map_err(|e| anyhow::anyhow!(\"Failed to get window handle: {e}\"))?;\n\n        let target = wgpu::SurfaceTargetUnsafe::RawHandle {\n            // Fall back to the display handle already provided via InstanceDescriptor::display.\n            raw_display_handle: None,\n            raw_window_handle: window_handle.as_raw(),\n        };\n\n        // Use the existing context's instance if available, otherwise create a new one.\n        // The surface must be created with the same instance that will be used for\n        // adapter selection, otherwise wgpu will panic.\n        let instance = gpu_context\n            .borrow()\n            .as_ref()\n            .map(|ctx| ctx.instance.clone())\n            .unwrap_or_else(|| WgpuContext::instance(Box::new(window.clone())));\n\n        // Safety: The caller guarantees that the window handle is valid for the\n        // lifetime of this renderer. In practice, the RawWindow struct is created","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui_wgpu/src/wgpu_renderer.rs#L252-L288","documentation":"Raised in `WgpuRenderer::new` (native only) when `window.window_handle()` / HasWindowHandle fails, so a raw window handle cannot be obtained to create the wgpu surface. Fires when the window is already closed/destroyed or the platform cannot vend a handle for the window type.","triggerScenarios":"Thrown at crates/gpui_wgpu/src/wgpu_renderer.rs:270 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create the renderer while the window is still alive and visible; do not defer past window destruction.","Ensure the window type correctly implements HasWindowHandle/HasDisplayHandle.","On Wayland/X11, verify the compositor connection is still valid.","Handle the error by surfacing a 'cannot initialize GPU' message to the user."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}