From 4f7cd45ea719eb93e380187f358d7608ea1c87c5 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 9 Mar 2021 22:24:57 -0500 Subject: [PATCH] Don't panic on pipeline creation errors --- wgpu-core/src/device/mod.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 60777f04a9..b06da2ad04 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1932,15 +1932,16 @@ impl Device { parent, }; - let raw = match unsafe { self.raw.create_compute_pipeline(&pipeline_desc, None) } { - Ok(pipeline) => pipeline, - Err(hal::pso::CreationError::OutOfMemory(_)) => { - return Err(pipeline::CreateComputePipelineError::Device( - DeviceError::OutOfMemory, - )) - } - other => panic!("Compute pipeline creation error: {:?}", other), - }; + let raw = + unsafe { self.raw.create_compute_pipeline(&pipeline_desc, None) }.map_err(|err| { + match err { + hal::pso::CreationError::OutOfMemory(_) => DeviceError::OutOfMemory, + _ => { + tracing::error!("failed to create compute pipeline: {}", err); + DeviceError::OutOfMemory + } + } + })?; let pipeline = pipeline::ComputePipeline { raw, @@ -2366,14 +2367,16 @@ impl Device { parent, }; // TODO: cache - let raw = unsafe { - self.raw - .create_graphics_pipeline(&pipeline_desc, None) - .map_err(|err| match err { + let raw = + unsafe { self.raw.create_graphics_pipeline(&pipeline_desc, None) }.map_err(|err| { + match err { hal::pso::CreationError::OutOfMemory(_) => DeviceError::OutOfMemory, - _ => panic!("failed to create graphics pipeline: {}", err), - })? - }; + _ => { + tracing::error!("failed to create graphics pipeline: {}", err); + DeviceError::OutOfMemory + } + } + })?; let pass_context = RenderPassContext { attachments: AttachmentData {