Skip to content

Fix the blade-atlas zoom crash and the memory growth while painting - #92

Merged
IAmJSD merged 1 commit into
mainfrom
t3code/f1761022
Sep 2, 2026
Merged

IAmJSD merged 1 commit into
mainfrom
t3code/f1761022

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Summary

A user crash report showed the app panicking at blade_atlas.rs:229 (Option::unwrap() on None) after a burst of atlas-texture churn during zooming. This PR fixes the crash in the gpui fork and removes the schist-side churn and leaks that fed it, which were also the main cause of memory growth while painting brush strokes.

gpui fork (fix landed as 6a7092a; main already pins 73c9da6, which contains it, so this PR no longer touches Cargo.toml)

An image too big for the shared 1024² atlas page gets a dedicated texture, queued for init/upload and drained at the next frame flush. Removing the image in between destroyed the texture slot, and the flush panicked indexing the empty Option. Removal now cancels the dead texture's pending work and returns the tile's rectangle to the allocator (shared atlases never reclaimed space before), and both flush paths skip freed slots — mirroring upstream zed's wgpu atlas.

schist

  • Zoom damping everywhere: ZoomIn/ZoomOut actions, the zoom tool, the menu bar and the navigator slider now arm the existing 120 ms view-gesture settle like wheel/pinch zoom, so rapid zoom stretches the previous image and rebuilds once instead of creating/destroying a window-sized (~8 MB) texture per step.
  • Retire replaced images: dropping an Arc<RenderImage> never frees its atlas slot. Every site that silently dropped one now routes through retire_image → drop_image: the layer/navigator thumbnails (rebuilt on every brush dab — the primary painting-memory leak), the far-zoom preview, the empty-viewport branch, and viewport invalidation on rotate-view, colour-transform rebuilds and per-document cache resets.
  • Undo byte budget: history kept up to 200 edits with no size cap; one stroke can retain ~50 MB of before/after tiles. A 1 GiB budget now evicts oldest edits (the newest always survives).
  • preview.dirty cap: the list is only drained at far zoom; it now collapses to a full-rebuild flag past 256 rects instead of growing per dab forever.

Testing

  • gpui fork: cargo check, cargo fmt -- --check, pinch + wayland unit tests, cargo check --target x86_64-pc-windows-gnu all clean.
  • schist: make build clean; 856 workspace tests pass, 0 failures.
  • Headless repro (Xvfb + lavapipe, the known rapid-ctrl+minus crash recipe): 26 rapid zoom keys → zero atlas rebuilds, no crash (previously one texture create/destroy per press, then the panic); 24 settled zooms → 12 create/destroy cycles through the fixed removal path, no crash; 15 brush strokes → remaining growth is bounded undo retention only.

Follow-ups (not in this PR)

  • An in-place atlas-update API in the gpui fork so the per-frame viewport rebuild while painting re-uploads pixels into the existing tile instead of create/destroy.
  • Byte-budget/LRU for TileCache/display_tiles.
  • Paint-tool allocation churn: sparse/u8 Stroke.coverage and borrowing Ink instead of cloning a TileMap per tile per dab.
  • Blade still destroys textures with no GPU fence; a deferred-destruction queue would close the (theoretical) stale-sprite hazard.

🤖 Generated with Claude Code

…red image slots

Rapid keyboard zoom crashed in gpui's blade atlas: every ctrl+minus rebuilt
the window-sized viewport image, and each rebuild created and destroyed a
dedicated GPU texture, racing the atlas's deferred texture initialization.
The fork side is fixed at the newly pinned gpui rev (removal now cancels a
dead texture's pending work and the flush skips freed slots); this commit
removes the churn and the leaks that fed it:

- Zoom entry points that skipped the 120 ms view-gesture damping (ZoomIn/
  ZoomOut actions, the zoom tool, the menu bar, the navigator slider) now
  arm it like wheel and pinch zoom, so a burst of steps stretches the
  previous image and rebuilds once settled.
- Dropping an Arc<RenderImage> never frees its atlas slot; every site that
  did so now routes through retire_image/drop_image: the layer and
  navigator thumbnails (rebuilt on every brush dab, the main source of
  memory growth while painting), the far-zoom preview image, the
  empty-viewport branch, and the viewport invalidation in rotate-view,
  colour-transform rebuilds and per-document cache resets. prepare_paint
  drains the retired list even with no document open.
- Undo history gains a byte budget (1 GiB) alongside the 200-edit cap: one
  stroke can retain tens of megabytes of before/after tiles, so the count
  cap alone let painting sessions hold gigabytes.
- The preview dirty-rect list, only drained at far zoom, now collapses to
  a full-rebuild flag past 256 rects instead of growing per dab forever.

Verified headlessly (Xvfb + lavapipe): 26 rapid zoom keys now cause zero
atlas rebuilds and no crash; 24 settled zooms cycle textures through the
fixed removal path cleanly; brush-stroke memory growth is down to bounded
undo retention.

Co-Authored-By: Claude Fable 5 <[email protected]>
@IAmJSD
IAmJSD merged commit 6497e79 into main Sep 2, 2026
4 checks passed
@IAmJSD
IAmJSD deleted the t3code/f1761022 branch September 2, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant