Skip to content

Fix GPUI crash when using cached view with Input#50665

Merged
mikayla-maki merged 2 commits into
zed-industries:mainfrom
xcb3d:fix/gpui-cached-view-input-crash-50456
May 14, 2026
Merged

Fix GPUI crash when using cached view with Input#50665
mikayla-maki merged 2 commits into
zed-industries:mainfrom
xcb3d:fix/gpui-cached-view-input-crash-50456

Conversation

@xcb3d

@xcb3d xcb3d commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

The draw() method was calling .pop() on next_frame.input_handlers to extract the active input handler for the platform window. This reduced the Vec length, making cached paint_range indices stale. On the next frame, when a cached view called reuse_paint(), it would index into rendered_frame.input_handlers with out-of-bounds indices, causing a panic: range start index 1 out of range for slice of length 0.

Fix: Use .last_mut().and_then(|h| h.take()) instead of .pop() to extract the handler without changing the Vec length. The slot becomes None, which is already handled by reuse_paint's .take() logic.

Closes #50456

Testing

  • All 83 existing GPUI unit tests pass
  • Manually verified with longbridge/gpui-component cargo run --example dock:
    • Switch to Input panel → type text → no crash ✅
    • Before fix: crash immediately on first keystroke

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist (N/A — no UI changes)

Release Notes:

  • Fixed a crash in GPUI when typing into an Input widget inside a cached view (#50456)

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 4, 2026
@maxdeviant maxdeviant changed the title Fix GPUI crash when using cached view with Input (#50456) Fix GPUI crash when using cached view with Input Mar 4, 2026
@xcb3d

xcb3d commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

The 4 test failures (agent_ui, vim) are unrelated to this change — this PR only modifies

crates/gpui/src/window.rs. These appear to be pre-existing flaky tests. Could you re-trigger CI? Thanks!

The draw() method was calling .pop() on next_frame.input_handlers to
extract the active input handler for the platform window. This reduced
the Vec length, making cached paint_range indices stale. On the next
frame, when a cached view called reuse_paint(), it would index into
rendered_frame.input_handlers with out-of-bounds indices, causing a
panic: 'range start index 1 out of range for slice of length 0'.

Fix: Use .last_mut().and_then(|h| h.take()) instead of .pop() to
extract the handler without changing the Vec length. The slot becomes
None, which is already handled by reuse_paint's .take() logic.
@xcb3d xcb3d force-pushed the fix/gpui-cached-view-input-crash-50456 branch from b4b2b40 to ffb03fb Compare March 6, 2026 18:04
@xcb3d

xcb3d commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi, the PR is ready for review.

@xcb3d

xcb3d commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @mikayla-maki, is this PR ready for merge ?

1 similar comment
@xcb3d

xcb3d commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Hi @mikayla-maki, is this PR ready for merge ?

@SomeoneToIgnore SomeoneToIgnore added the area:gpui GPUI rendering framework support label Apr 30, 2026

@mikayla-maki mikayla-maki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice solution!

@mikayla-maki mikayla-maki enabled auto-merge May 14, 2026 15:22
@mikayla-maki mikayla-maki added this pull request to the merge queue May 14, 2026
Merged via the queue into zed-industries:main with commit a221a86 May 14, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpui GPUI rendering framework support cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPUI crashes when use cached view with Input

5 participants