Skip to content

Commit

Permalink
Wrap all validation logs with catch_unwinds (gfx-rs#2511)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Apr 19, 2022
1 parent a196670 commit 5cd16f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
4 changes: 3 additions & 1 deletion wgpu-hal/src/dx12/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ unsafe extern "system" fn output_debug_string_handler(
return excpt::EXCEPTION_CONTINUE_SEARCH;
}

log::log!(level, "{}", message);
let _ = std::panic::catch_unwind(|| {
log::log!(level, "{}", message);
});

if cfg!(debug_assertions) && level == log::Level::Error {
// Panicking behind FFI is UB, so we just exit.
Expand Down
18 changes: 10 additions & 8 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,16 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
_ => unreachable!(),
};

log::log!(
log_severity,
"GLES: [{}/{}] ID {} : {}",
source_str,
type_str,
id,
message
);
let _ = std::panic::catch_unwind(|| {
log::log!(
log_severity,
"GLES: [{}/{}] ID {} : {}",
source_str,
type_str,
id,
message
);
});

if cfg!(debug_assertions) && log_severity == log::Level::Error {
std::process::exit(1);
Expand Down
32 changes: 21 additions & 11 deletions wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ unsafe extern "system" fn debug_utils_messenger_callback(
CStr::from_ptr(cd.p_message).to_string_lossy()
};

log::log!(
level,
"{:?} [{} (0x{:x})]\n\t{}",
message_type,
message_id_name,
cd.message_id_number,
message,
);
let _ = std::panic::catch_unwind(|| {
log::log!(
level,
"{:?} [{} (0x{:x})]\n\t{}",
message_type,
message_id_name,
cd.message_id_number,
message,
);
});

if cd.queue_label_count != 0 {
let labels = slice::from_raw_parts(cd.p_queue_labels, cd.queue_label_count as usize);
Expand All @@ -64,7 +66,10 @@ unsafe extern "system" fn debug_utils_messenger_callback(
.map(|lbl| CStr::from_ptr(lbl).to_string_lossy())
})
.collect::<Vec<_>>();
log::log!(level, "\tqueues: {}", names.join(", "));

let _ = std::panic::catch_unwind(|| {
log::log!(level, "\tqueues: {}", names.join(", "));
});
}

if cd.cmd_buf_label_count != 0 {
Expand All @@ -78,7 +83,10 @@ unsafe extern "system" fn debug_utils_messenger_callback(
.map(|lbl| CStr::from_ptr(lbl).to_string_lossy())
})
.collect::<Vec<_>>();
log::log!(level, "\tcommand buffers: {}", names.join(", "));

let _ = std::panic::catch_unwind(|| {
log::log!(level, "\tcommand buffers: {}", names.join(", "));
});
}

if cd.object_count != 0 {
Expand All @@ -99,7 +107,9 @@ unsafe extern "system" fn debug_utils_messenger_callback(
)
})
.collect::<Vec<_>>();
log::log!(level, "\tobjects: {}", names.join(", "));
let _ = std::panic::catch_unwind(|| {
log::log!(level, "\tobjects: {}", names.join(", "));
});
}

vk::FALSE
Expand Down

0 comments on commit 5cd16f1

Please sign in to comment.