# gpui_wgpu: Fix wgpu renderer teardown panic \(\#60160\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/56009f39bb916be80baace86919267cf0e09035c)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 56009f39bb916be80baace86919267cf0e09035c

Requested commit: 56009f39bb916be80baace86919267cf0e09035c

Commit: 56009f39bb916be80baace86919267cf0e09035c

Tree: f6f90d2546b44bb352d5fa72452b1e5f6dce60ed

Author: Philipp Schaffrath

Committer: GitHub

## Message

```
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>
```

## Parents

- [5a7d414a23938c5efb674d0c2948813e37448eea](https://git.cafe/gitcafe/zed/commit/5a7d414a23938c5efb674d0c2948813e37448eea?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/56009f39bb916be80baace86919267cf0e09035c?format=markdown)
