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.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
fix(gui): keep the previous OpenGL frame when a paint gives up
RoversX0bab069681bb
diff --git a/wezterm-gui/src/renderstate.rs b/wezterm-gui/src/renderstate.rsindex 188729d6..5f04f2a0 100644--- a/wezterm-gui/src/renderstate.rs+++ b/wezterm-gui/src/renderstate.rs@@ -100,7 +100,9 @@ pub enum RenderContext {}pub enum RenderFrame<'a> {- Glium(&'a mut glium::Frame),+ /// Created by the draw: a paint that gives up never makes one, so+ /// nothing is swapped and the previous frame stays on screen.+ Glium(&'a mut Option<glium::Frame>),WebGpu,}@@ -514,7 +516,15 @@ impl TripleVertexBuffer {}pub fn vertex_index_count(&self) -> (usize, usize) {- let num_quads = *self.next_quad.borrow();+ let next = *self.next_quad.borrow();+ // A pass that gave up before allocated_more_quads could grow the+ // buffers leaves the count past their end. Such frames are not+ // drawn; should one get here anyway, draw only what the buffers+ // hold, and count it.+ if next > self.capacity {+ crate::perf::log_counter("draw_quads_clamped", next - self.capacity);+ }+ let num_quads = next.min(self.capacity);(num_quads * VERTICES_PER_CELL, num_quads * INDICES_PER_CELL)}diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex a33d9140..0f5f3cae 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -6111,7 +6111,9 @@ impl SettingsWindow {Ok(false) => break,Err(err) => {log::error!("settings window quad allocation failed: {err:#}");- break;+ // The layers hold a pass that ran out of quads:+ // keep the previous frame rather than draw it.+ return Ok(false);}}}diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 9223d117..bc0f087d 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -5239,23 +5239,21 @@ impl TermWindow {return false;}- let mut frame = glium::Frame::new(- Rc::clone(&gl),- (- self.dimensions.pixel_width as u32,- self.dimensions.pixel_height as u32,- ),- );+ // Created by the draw: a paint that gives up leaves it None, nothing+ // is swapped, and the previous frame stays on screen.+ let mut frame = None;let painted = self.paint_impl(&mut RenderFrame::Glium(&mut frame));- let outcome = match painted {- Ok(outcome) if outcome.draw_submitted => outcome,- painted => {+ let (outcome, frame) = match (painted, frame) {+ (Ok(outcome), Some(frame)) if outcome.draw_submitted => (outcome, frame),+ (painted, frame) => {if let Err(err) = painted {log::error!("failed to draw OpenGL frame: {err:#}");}// glium panics when an unfinished Frame is dropped.- if let Err(err) = window.finish_frame(frame) {- log::error!("failed to present OpenGL frame: {err:#}");+ if let Some(frame) = frame {+ if let Err(err) = window.finish_frame(frame) {+ log::error!("failed to present OpenGL frame: {err:#}");+ }}self.discard_unpresented_pane_output();return false;diff --git a/wezterm-gui/src/termwindow/render/draw.rs b/wezterm-gui/src/termwindow/render/draw.rsindex fb237748..3a5d9da7 100644--- a/wezterm-gui/src/termwindow/render/draw.rs+++ b/wezterm-gui/src/termwindow/render/draw.rs@@ -11,7 +11,9 @@ use ::window::glium::uniforms::{};use ::window::glium::{BlendingFunction, LinearBlendingFactor, Surface};use ::window::{Appearance, Dimensions, WindowDecorations, WindowState};+use anyhow::Context;use config::FreeTypeLoadTarget;+use std::rc::Rc;const LINUX_WINDOW_CORNER_RADIUS: f32 = 16.0;const LINUX_WINDOW_BORDER_WIDTH: f32 = 1.0;@@ -680,7 +682,15 @@ pub(crate) fn draw_opengl_layers(impl crate::TermWindow {pub fn call_draw(&mut self, frame: &mut RenderFrame) -> anyhow::Result<()> {match frame {- RenderFrame::Glium(ref mut frame) => self.call_draw_glium(frame),+ RenderFrame::Glium(frame) => {+ let gl = Rc::clone(self.gl.as_ref().context("OpenGL context missing")?);+ let size = (+ self.dimensions.pixel_width as u32,+ self.dimensions.pixel_height as u32,+ );+ let frame = frame.get_or_insert_with(|| glium::Frame::new(gl, size));+ self.call_draw_glium(frame)+ }RenderFrame::WebGpu => self.call_draw_webgpu(),}}diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex 3e810b74..2dfb8d79 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -1089,9 +1089,10 @@ impl crate::TermWindow {// couple of frames until the requested repaint lands -- a visible// black flash on every font-size change. Skipping the present keeps// the previous complete frame on screen instead, which nobody can- // see. Only WebGpu can skip: the glium frame was created by do_paint- // and will be swapped regardless, so an unpainted frame there would- // present undefined content, which is worse than a partial one.+ // see. Both renderers skip: glium creates its frame in the draw, so+ // a frame that is not drawn is never swapped. Not even a partial+ // frame is left once a pass runs out of quads: every one past the+ // end is written over the first, the window background.let mut present_frame = true;let mut frame_complete = false;// Held outside the loop so the memory counters can be emitted on@@ -1119,6 +1120,9 @@ impl crate::TermWindow {}Err(err) => {log::error!("{:#}", err);+ // The pass ran out of quads and they could not grow:+ // keep the previous frame, as the arms below do.+ present_frame = false;break 'pass;}},@@ -1303,7 +1307,7 @@ impl crate::TermWindow {if let Some(render_state) = self.render_state.as_ref() {render_state.dedicated_images.borrow_mut().end_frame();}- let draw_result = if present_frame || !matches!(frame, RenderFrame::WebGpu) {+ let draw_result = if present_frame {self.call_draw(frame).map(|_| true)} else {Ok(false)