Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

gui: never panic on the line quad scratch recorder

RoversX4d7fd14cb5c1
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index 63879f07..e3f8d2db 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -925,7 +925,9 @@ impl crate::TermWindow {
}
crate::perf::log_counter(
"line_quad_scratch_bytes",
- self.line_quad_scratch.borrow().resident_bytes(),
+ self.line_quad_scratch
+ .try_borrow()
+ .map_or(0, |scratch| scratch.resident_bytes()),
);
if let Some(render_state) = self.render_state.as_ref() {
let glyphs = render_state.glyph_cache.borrow();
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 5fa47986..89513880 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -1940,8 +1940,18 @@ impl crate::TermWindow {
// moved out at exact size below, rather than growing a
// fresh allocator from zero on every miss. Recycled on
// entry so an early `?` return leaves nothing stale.
- let mut buf = self.term_window.line_quad_scratch.borrow_mut();
- buf.recycle();
+ // No painter re-enters this while a line is being
+ // recorded; should one ever do so, that line falls back
+ // to a private allocator rather than panicking mid-paint.
+ let mut scratch_guard = self.term_window.line_quad_scratch.try_borrow_mut();
+ let mut fallback = HeapQuadAllocator::default();
+ let buf: &mut HeapQuadAllocator = match scratch_guard.as_mut() {
+ Ok(scratch) => {
+ scratch.recycle();
+ &mut **scratch
+ }
+ Err(_) => &mut fallback,
+ };
let next_due = self.term_window.has_animation.borrow_mut().take();
let shape_key = LineToEleShapeCacheKey {
@@ -2004,7 +2014,7 @@ impl crate::TermWindow {
allow_images: true,
simple_shaping: false,
},
- &mut TripleLayerQuadAllocator::Heap(&mut *buf),
+ &mut TripleLayerQuadAllocator::Heap(buf),
)
.context("render_screen_line")?;
@@ -2013,7 +2023,7 @@ impl crate::TermWindow {
replay_line(
self.layers,
- &*buf,
+ buf,
self.scroll_px,
self.pane_clip,
line_idx,
@@ -2039,7 +2049,7 @@ impl crate::TermWindow {
None
},
};
- drop(buf);
+ drop(scratch_guard);
let weight = crate::termwindow::render::estimate_line_quad_entry_bytes(
&quad_key,
&quad_value,