From 8b355baede3e2c873a820b123d3403a05d75d993 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sat, 21 Jan 2023 12:54:30 +0100 Subject: [PATCH] Catch panic from Instance::preinitialized --- src/vk_layer/mod.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/vk_layer/mod.rs b/src/vk_layer/mod.rs index 23d7779..4240975 100644 --- a/src/vk_layer/mod.rs +++ b/src/vk_layer/mod.rs @@ -165,12 +165,26 @@ pub(crate) extern "system" fn create_instance( // DXVK workaround, it creates the instance twice with different properties if ext_names.contains(&VkString::new("VK_KHR_surface")) { unsafe { - let ins = match Instance::preinitialized( - *instance, - proc_addr, - &ext_names, - (*(*create_info).pApplicationInfo).apiVersion, - ) { + let panic_result = + match std::panic::catch_unwind(|| -> anyhow::Result> { + Instance::preinitialized( + *instance, + proc_addr, + &ext_names, + (*(*create_info).pApplicationInfo).apiVersion, + ) + }) { + Ok(panic_ok) => panic_ok, + Err(err) => { + write_log!(format!( + "catched a panic from Instance::preinitialized: {:?}", + err + )); + return VK_ERROR_INITIALIZATION_FAILED; + } + }; + + let ins = match panic_result { Ok(ins) => ins, Err(err) => { write_log!(format!("-> local instance creation failed: {:?}", err));