From 8f241af0cf4c0bd281fb9ce8ab08f2b452641fb1 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Thu, 12 Dec 2024 17:25:01 +0100 Subject: [PATCH] Fail early --- crates/egui-wgpu/src/capture.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/egui-wgpu/src/capture.rs b/crates/egui-wgpu/src/capture.rs index a50468592f6..e15b659d7c7 100644 --- a/crates/egui-wgpu/src/capture.rs +++ b/crates/egui-wgpu/src/capture.rs @@ -190,19 +190,19 @@ impl CaptureState { let format = self.texture.format(); let tex_extent = self.texture.size(); let padding = self.padding; + let to_rgba = match format { + wgpu::TextureFormat::Rgba8Unorm => [0, 1, 2, 3], + wgpu::TextureFormat::Bgra8Unorm => [2, 1, 0, 3], + _ => { + log::error!("Screen can't be captured unless the surface format is Rgba8Unorm or Bgra8Unorm. Current surface format is {:?}", format); + return; + } + }; buffer_slice.map_async(wgpu::MapMode::Read, move |result| { if let Err(err) = result { log::error!("Failed to map buffer for reading: {:?}", err); return; } - let to_rgba = match format { - wgpu::TextureFormat::Rgba8Unorm => [0, 1, 2, 3], - wgpu::TextureFormat::Bgra8Unorm => [2, 1, 0, 3], - _ => { - log::error!("Screen can't be captured unless the surface format is Rgba8Unorm or Bgra8Unorm. Current surface format is {:?}", format); - return; - } - }; let buffer_slice = buffer.slice(..); let mut pixels = Vec::with_capacity((tex_extent.width * tex_extent.height) as usize); @@ -229,7 +229,8 @@ impl CaptureState { size: [tex_extent.width as usize, tex_extent.height as usize], pixels, }, - )).ok(); + )) + .ok(); ctx.request_repaint(); }); }