Skip to content

Fix crash in WgpuAtlas when viewing a screen share#53088

Merged
osyvokon merged 2 commits intomainfrom
fix-screensharing-crash
Apr 3, 2026
Merged

Fix crash in WgpuAtlas when viewing a screen share#53088
osyvokon merged 2 commits intomainfrom
fix-screensharing-crash

Conversation

@osyvokon
Copy link
Copy Markdown
Contributor

@osyvokon osyvokon commented Apr 3, 2026

When atlas tiles are rapidly allocated and freed (e.g. watching a shared screen in Collab), a texture can become unreferenced and be removed while GPU uploads for it are still pending. On the next frame, flush_uploads indexes into the now-empty texture slot and panics:

  thread 'main' panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:231:40:
  texture must exist...

  #11 core::option::expect_failed
  #12 gpui_wgpu::wgpu_atlas::WgpuAtlas::before_frame
  #13 gpui_wgpu::wgpu_renderer::WgpuRenderer::draw

This change drains pending uploads for a texture when it becomes unreferenced in remove, and skips uploads for missing textures in flush_uploads as a safety net.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed occasional crashes when viewing a screen share

osyvokon added 2 commits April 3, 2026 20:04
When atlas tiles are rapidly allocated and freed (e.g. watching a shared
screen in Collab), a texture can become unreferenced and be removed while
GPU uploads for it are still pending. On the next frame, `flush_uploads`
indexes into the now-empty texture slot and panics:

```
  thread 'main' panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:231:40:
  texture must exist...

  #11 core::option::expect_failed
  #12 gpui_wgpu::wgpu_atlas::WgpuAtlas::before_frame
  #13 gpui_wgpu::wgpu_renderer::WgpuRenderer::draw
```

Drain pending uploads for a texture when it becomes unreferenced in
`remove`, and skip uploads for missing textures in `flush_uploads` as a
safety net.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 3, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Apr 3, 2026
@osyvokon
Copy link
Copy Markdown
Contributor Author

osyvokon commented Apr 3, 2026

@ConradIrwin Could you review? This is a fix for an issue I'm regularly hitting on a Linux machine. Agentically generated from a crash dump. I've made sure that the test fails without the fix.

Copy link
Copy Markdown
Member

@ConradIrwin ConradIrwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, see also #51996

@osyvokon osyvokon merged commit e4ebd3a into main Apr 3, 2026
41 checks passed
@osyvokon osyvokon deleted the fix-screensharing-crash branch April 3, 2026 19:31
rtfeldman pushed a commit that referenced this pull request Apr 4, 2026
When atlas tiles are rapidly allocated and freed (e.g. watching a shared
screen in Collab), a texture can become unreferenced and be removed
while GPU uploads for it are still pending. On the next frame,
`flush_uploads` indexes into the now-empty texture slot and panics:

```
  thread 'main' panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:231:40:
  texture must exist...

  #11 core::option::expect_failed
  #12 gpui_wgpu::wgpu_atlas::WgpuAtlas::before_frame
  #13 gpui_wgpu::wgpu_renderer::WgpuRenderer::draw
```

This change drains pending uploads for a texture when it becomes
unreferenced in `remove`, and skips uploads for missing textures in
`flush_uploads` as a safety net.

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Fixed occasional crashes when viewing a screen share
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
)

When atlas tiles are rapidly allocated and freed (e.g. watching a shared
screen in Collab), a texture can become unreferenced and be removed
while GPU uploads for it are still pending. On the next frame,
`flush_uploads` indexes into the now-empty texture slot and panics:

```
  thread 'main' panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:231:40:
  texture must exist...

  zed-industries#11 core::option::expect_failed
  zed-industries#12 gpui_wgpu::wgpu_atlas::WgpuAtlas::before_frame
  zed-industries#13 gpui_wgpu::wgpu_renderer::WgpuRenderer::draw
```

This change drains pending uploads for a texture when it becomes
unreferenced in `remove`, and skips uploads for missing textures in
`flush_uploads` as a safety net.

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Fixed occasional crashes when viewing a screen share
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants