From 64d5f948e43b4be93e3a4541c87dcce74c948df4 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 26 Jul 2024 10:10:23 +0200 Subject: [PATCH] Workaround for wgpu crash when surface is dropped last (#4876) * Fixes https://github.com/emilk/egui/issues/4874 * Details see https://github.com/gfx-rs/wgpu/pull/6052 --- crates/egui-wgpu/src/winit.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 46db8821..f0644ee1 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -96,6 +96,17 @@ pub struct Painter { surfaces: ViewportIdMap, } +impl Drop for Painter { + fn drop(&mut self) { + // Drop surfaces before dropping the render state. + // + // This is a workaround for a bug in wgpu 22.0.0. + // Fixed in https://github.com/gfx-rs/wgpu/pull/6052 + // Remove with wgpu 22.1.0 update! + self.surfaces.clear(); + } +} + impl Painter { /// Manages [`wgpu`] state, including surface state, required to render egui. ///