gpui_wgpu: Fix wgpu renderer teardown panic (#60160)
# Objective Opening and closing windows quickly on Linux could crash the renderer with a `GPU resources not available` panic. The `gpui_wgpu` renderer keeps its GPU resources in an `Option` that is cleared when a window is torn down, and also while device-loss recovery is pending. On Wayland the window's `Drop` releases those resources synchronously but defers unregistering the surface to a later task, so a compositor resize or transparency event can still reach the renderer in that short gap. `update_drawable_size` and `update_transparency` assumed the resources were always present and called an accessor that panics when they are not. I am not certain if there is a good case to reproduce this in zed, but I had encountered it in my own GPUI app. ## Solution Make `update_drawable_size` and `update_transparency` tolerate missing GPU resources by skipping the surface reconfiguration instead of panicking, matching how the rest of the renderer already guards this state. The requested size and alpha mode are still recorded before the guard, so they take effect if the renderer's resources are recreated, for example after device-loss recovery. ## Testing Tested on Linux with Wayland. - Reproduced by opening and closing windows quickly, which previously panicked with `GPU resources not available`. With this change the panic no longer occurs. This was reproducible on a debug build or a weak/slow device. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes (not sure if worth mentioning): - Fixed a crash that could occur when opening and closing windows quickly on Linux Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
1 parent
aa7591f73f
commit
6a9bf6498f
1 file changed
+6
-2
@@ -962,7 +962,9 @@ impl WgpuRenderer {
|
||||
self.surface_config.height = clamped_height.max(1);
|
||||
let surface_config = self.surface_config.clone();
|
||||
|
||||
let resources = self.resources_mut();
|
||||
let Some(resources) = self.resources.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Wait for any in-flight GPU work to complete before destroying textures
|
||||
if let Err(e) = resources.device.poll(wgpu::PollType::Wait {
|
||||
@@ -1035,7 +1037,9 @@ impl WgpuRenderer {
|
||||
let surface_config = self.surface_config.clone();
|
||||
let path_sample_count = self.rendering_params.path_sample_count;
|
||||
let dual_source_blending = self.dual_source_blending;
|
||||
let resources = self.resources_mut();
|
||||
let Some(resources) = self.resources.as_mut() else {
|
||||
return;
|
||||
};
|
||||
resources
|
||||
.surface
|
||||
.configure(&resources.device, &surface_config);
|
||||
|
||||
Reference in new issue
Block a user