zed/crates/gpui_wgpu
Philipp Schaffrath 56009f39bb
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>
2026-07-07 16:52:35 +00:00
..
benches gpui_wgpu: Respect buffer_font_fallbacks setting (#54878) 2026-05-15 15:34:18 +00:00
src gpui_wgpu: Fix wgpu renderer teardown panic (#60160) 2026-07-07 16:52:35 +00:00
Cargo.toml gpui_wgpu: Bump cosmic-text to v0.19.0 (#56988) 2026-05-24 08:33:56 +00:00
LICENSE-APACHE gpui: Extract gpui_platform out of gpui (#49277) 2026-02-19 18:57:49 +01:00