From fc0b4cfe9566d7a3e49dcb344b201c87f86cf9f3 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 2 Jul 2025 16:01:00 +0200 Subject: [PATCH] Don't call `destroy` on textures on webgl --- crates/egui-wgpu/src/lib.rs | 1 + crates/egui-wgpu/src/renderer.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index 63d20cdfb..11990d415 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -234,6 +234,7 @@ impl RenderState { let renderer = Renderer::new( &device, + adapter.get_info().backend, target_format, depth_format, msaa_samples, diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index 473c73028..3cb933d2d 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -196,6 +196,8 @@ pub struct Renderer { dithering: bool, + backend: wgpu::Backend, + /// Storage for resources shared with all invocations of [`CallbackTrait`]'s methods. /// /// See also [`CallbackTrait`]. @@ -209,6 +211,7 @@ impl Renderer { /// [`wgpu::TextureFormat::Bgra8Unorm`], i.e. in gamma-space. pub fn new( device: &wgpu::Device, + backend: wgpu::Backend, output_color_format: wgpu::TextureFormat, output_depth_format: Option, msaa_samples: u32, @@ -403,6 +406,9 @@ impl Renderer { next_user_texture_id: 0, samplers: HashMap::default(), dithering, + + backend, + callback_resources: CallbackResources::default(), } } @@ -687,7 +693,11 @@ impl Renderer { pub fn free_texture(&mut self, id: &epaint::TextureId) { if let Some(texture) = self.textures.remove(id).and_then(|t| t.texture) { - texture.destroy(); + // TODO: explain why. + let is_webgl = self.backend == wgpu::Backend::Gl && cfg!(target_arch = "wasm32"); + if !is_webgl { + texture.destroy(); + } } }