{"record":{"id":"9811e23ec06228b1","repo":"zed-industries/zed","slug":"device-lost-err","errorCode":null,"errorMessage":"Device lost: {err}","messagePattern":"Device lost: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/gpui_windows/src/events.rs","lineNumber":1263,"sourceCode":"    }\n\n    fn handle_window_visibility_changed(&self, handle: HWND, wparam: WPARAM) -> Option<isize> {\n        if wparam.0 == 1 {\n            self.draw_window(handle, false);\n        }\n        None\n    }\n\n    fn handle_device_lost(&self, lparam: LPARAM) -> Option<isize> {\n        let devices = lparam.0 as *const DirectXDevices;\n        let devices = unsafe { &*devices };\n        if let Err(err) = self\n            .state\n            .renderer\n            .borrow_mut()\n            .handle_device_lost(&devices)\n        {\n            panic!(\"Device lost: {err}\");\n        }\n        // Make sure the first `draw_window` after recovery (whether it comes\n        // from the forced WM_GPUI_FORCE_UPDATE_WINDOW or a stray WM_PAINT in\n        // between) is treated as a forced render so it both clears\n        // `skip_draws` and bypasses the view cache.\n        self.state.force_render_pending.set(true);\n        Some(0)\n    }\n\n    fn handle_dm_pointer_hit_test(&self, wparam: WPARAM) -> Option<isize> {\n        self.state.direct_manipulation.on_pointer_hit_test(wparam);\n        None\n    }\n\n    #[inline]\n    fn draw_window(&self, handle: HWND, force_render: bool) -> Option<isize> {\n        let Some(_guard) = self.state.draw_coordinator.try_begin_draw() else {\n            log::debug!(\"deferring re-entrant draw of window {handle:?}\");","sourceCodeStart":1245,"sourceCodeEnd":1281,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui_windows/src/events.rs#L1245-L1281","documentation":"When Direct3D reports the GPU device was removed or reset, the Windows event handler asks the renderer to recreate its DirectX device and dependent state via handle_device_lost. If that recovery fails and returns Err, the handler panics with the recovery error. So the panic means not just 'the driver reset the GPU' but 'GPUI could not rebuild its device afterwards' - typically the adapter is gone or keeps failing.","triggerScenarios":"A device-lost window message arrives (driver timeout/TDR, docking/undocking a hybrid-graphics laptop, driver upgrade while the app runs, VRAM exhaustion) and the subsequent device/swapchain recreation inside handle_device_lost fails, propagating Err into the panic.","commonSituations":"Windows TDR events visible in Event Viewer as 'Display driver ... stopped responding and has successfully recovered' (Event 4101); eGPU hot-docking; driver upgrades forcing device removal; factory-overclocked GPUs failing under load.","solutions":["Update the GPU driver - most device-lost-then-recovery-failed chains are driver bugs","Check Windows Event Viewer (System log) at the crash time for Event 4101 / driver resets to identify the trigger","Reduce GPU load and VRAM pressure (close GPU-heavy apps) to avoid TDR timeouts","If TDRs recur, extend the TdrDelay registry value or remove overclocks; otherwise report upstream with the err text from the panic"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// run the window/message loop under a supervisor and relaunch after GPU loss\nloop {\n    let ok = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| run_gpui_window()));\n    if ok.is_ok() {\n        break;\n    }\n    std::thread::sleep(std::time::Duration::from_secs(2)); // let the driver settle before retry\n}","preventionTips":["Keep GPU drivers current, especially on hybrid-graphics laptops","Restart the app after GPU topology changes (docking, eGPU, driver installs) instead of assuming recovery","Watch Event Viewer Event 4101 (TDR) on machines that hit this; fixing the TDR fixes the panic","Reduce sustained GPU load so the driver never hits timeout thresholds"],"tags":["windows","directx","gpu","device-lost","gpui"],"backgroundTag":"gpu-device-lost","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}