From 4a52073f7c93e568190f4a7513aff8e29d8ade18 Mon Sep 17 00:00:00 2001 From: unohee Date: Sun, 25 Oct 2026 10:23:58 +0900 Subject: [PATCH 1/2] fix(wgpu): skip drawing while the surface has zero area Configuring a surface or creating a texture with a zero dimension is a wgpu validation error, and wgpu's default handler panics on it inside baseview's frame/event callback, where a plug-in host aborts. Hosts can collapse an embedded view to 0x0. Measured with de-artifact on a Windows 10 VM: SetWindowPos(editor child, 0x0) -> 'Both Surface width and height must be non-zero' -> exit 0xC0000409 (AUD-2367). --- src/renderer/wgpu/renderer.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/renderer/wgpu/renderer.rs b/src/renderer/wgpu/renderer.rs index 840c8b8..e4a332e 100644 --- a/src/renderer/wgpu/renderer.rs +++ b/src/renderer/wgpu/renderer.rs @@ -256,6 +256,20 @@ impl Renderer { ) }; + // Configuring a surface or creating a texture with a zero dimension is a + // wgpu validation error, and wgpu's default handler panics on it -- inside + // baseview's frame/event callback, where a plug-in host aborts. Hosts can + // collapse an embedded view to 0x0, so draw nothing until it has an area. + // Texture and buffer writes above are already queued on `queue` and land + // with the next submit; frees are applied now so ids are not leaked. + if canvas_width == 0 || canvas_height == 0 { + let mut renderer = self.render_state.renderer.write(); + for id in &full_output.textures_delta.free { + renderer.free_texture(id); + } + return; + } + if self.width != canvas_width || self.height != canvas_height || self.msaa_texture_view.is_none() From 750ce16f2a3f289accce71456d5d7ba239fe49b7 Mon Sep 17 00:00:00 2001 From: unohee Date: Sun, 25 Oct 2026 11:06:09 +0900 Subject: [PATCH 2/2] fix(wgpu): render through D3D12 or GL on Windows, not Vulkan wgpu enumerates Vulkan before D3D12 and keeps that order between adapters of the same type, so a normal Windows GPU rendered the editor through Vulkan and pulled every Vulkan implicit layer (overlays, capture and vendor layers) into the plug-in host's process. D3D12 drives the same GPUs and its WARP adapter covers machines with no GPU driver; GL remains for GPUs without a D3D12 driver. WGPU_BACKEND still overrides the default for diagnosis (de-artifact AUD-2367). --- src/renderer/wgpu/renderer.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/renderer/wgpu/renderer.rs b/src/renderer/wgpu/renderer.rs index e4a332e..5bd2078 100644 --- a/src/renderer/wgpu/renderer.rs +++ b/src/renderer/wgpu/renderer.rs @@ -8,7 +8,7 @@ use baseview::{PhySize, Window}; use egui::FullOutput; use egui_wgpu::{ wgpu::{ - Color, CommandEncoderDescriptor, Extent3d, Instance, InstanceDescriptor, + Backends, Color, CommandEncoderDescriptor, Extent3d, Instance, InstanceDescriptor, RenderPassColorAttachment, RenderPassDescriptor, Surface, SurfaceConfiguration, SurfaceTargetUnsafe, TextureDescriptor, TextureDimension, TextureUsages, TextureView, TextureViewDescriptor, @@ -49,6 +49,24 @@ impl Default for GraphicsConfig { const MSAA_SAMPLES: u32 = 4; +/// Backends the editor may render through. `WGPU_BACKEND` still overrides this, +/// which is useful when diagnosing a user's machine. +/// +/// On Windows, Vulkan is left out. wgpu enumerates Vulkan before D3D12 and keeps +/// that order between adapters of the same type, so a normal GPU would otherwise +/// render through Vulkan -- loading every Vulkan implicit layer (overlays, +/// capture and vendor layers) into the plug-in host's process. D3D12 drives +/// every GPU Vulkan would here, and its WARP software adapter covers machines +/// without a GPU driver; GL stays as a last hardware option for GPUs with no +/// D3D12 driver (pre-Haswell Intel, for one). +fn default_backends(windows: bool) -> Backends { + if windows { + Backends::DX12 | Backends::GL + } else { + Backends::all() + } +} + pub struct Renderer { render_state: Arc, surface: Surface<'static>, @@ -74,7 +92,10 @@ fn win32_raw_window_handle_06( impl Renderer { pub fn new(window: &Window, config: GraphicsConfig) -> Result { - let instance = Instance::new(&InstanceDescriptor::default()); + let instance = Instance::new(&InstanceDescriptor { + backends: Backends::from_env().unwrap_or_else(|| default_backends(cfg!(windows))), + ..Default::default() + }); let raw_display_handle = window.raw_display_handle(); let raw_window_handle = window.raw_window_handle(); @@ -352,6 +373,15 @@ mod tests { use super::win32_raw_window_handle_06; + #[test] + fn windows_backends_leave_out_vulkan_but_keep_d3d12_and_gl() { + let windows = super::default_backends(true); + assert!(!windows.contains(super::Backends::VULKAN)); + assert!(windows.contains(super::Backends::DX12)); + assert!(windows.contains(super::Backends::GL)); + assert_eq!(super::default_backends(false), super::Backends::all()); + } + #[test] fn parented_win32_handle_allows_a_null_hinstance() { let mut handle = Win32WindowHandle::empty();