diff --git a/crates/gpui_wgpu/src/wgpu_renderer.rs b/crates/gpui_wgpu/src/wgpu_renderer.rs index 95d64d952373f303c1015669ee90a93b5d179dd5..14f267deb87f482c8e7905144eca97ecf2dec68f 100644 --- a/crates/gpui_wgpu/src/wgpu_renderer.rs +++ b/crates/gpui_wgpu/src/wgpu_renderer.rs @@ -5,6 +5,7 @@ use gpui::{ PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size, SubpixelSprite, Underline, get_gamma_correction_ratios, }; +use log::warn; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::num::NonZeroU64; use std::sync::Arc; @@ -776,6 +777,20 @@ impl WgpuRenderer { let height = size.height.0 as u32; if width != self.surface_config.width || height != self.surface_config.height { + // Wait for any in-flight GPU work to complete before destroying textures + if let Err(e) = self.device.poll(wgpu::PollType::Wait { + submission_index: None, + timeout: None, + }) { + warn!("Failed to poll device during resize: {e:?}"); + } + + // Destroy old textures before allocating new ones to avoid GPU memory spikes + self.path_intermediate_texture.destroy(); + if let Some(ref texture) = self.path_msaa_texture { + texture.destroy(); + } + self.surface_config.width = width.max(1); self.surface_config.height = height.max(1); self.surface.configure(&self.device, &self.surface_config);