From a477c2008db27db0b9f745715e119b3ee7ab7818 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 11 Jul 2024 13:47:13 -0600 Subject: [PATCH] Panic less in initialization --- blade-graphics/src/vulkan/init.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 8474e5ef..a2b74c2f 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -363,10 +363,14 @@ impl super::Context { } }; - let vk_surface = surface_handles.map(|(wh, dh)| { - ash_window::create_surface(&entry, &core_instance, dh.as_raw(), wh.as_raw(), None) - .unwrap() - }); + let vk_surface = if let Some((wh, dh)) = surface_handles { + Some( + ash_window::create_surface(&entry, &core_instance, dh.as_raw(), wh.as_raw(), None) + .map_err(|e| NotSupportedError::VulkanError(e))?, + ) + } else { + None + }; let instance = super::Instance { @@ -381,7 +385,10 @@ impl super::Context { core: core_instance, }; - let physical_devices = instance.core.enumerate_physical_devices().unwrap(); + let physical_devices = instance + .core + .enumerate_physical_devices() + .map_err(|e| NotSupportedError::VulkanError(e))?; let (physical_device, capabilities) = physical_devices .into_iter() .find_map(|phd| {