diff --git a/crates/gpui/src/platform/wgpu/wgpu_renderer.rs b/crates/gpui/src/platform/wgpu/wgpu_renderer.rs index 25b13ce1100e25522ffa8295b47540fc6f158a5f..71f6660148e6d57fec36c0579042096d2750fae7 100644 --- a/crates/gpui/src/platform/wgpu/wgpu_renderer.rs +++ b/crates/gpui/src/platform/wgpu/wgpu_renderer.rs @@ -5,6 +5,7 @@ use crate::{ Underline, get_gamma_correction_ratios, }; use bytemuck::{Pod, Zeroable}; +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);