From e66e9a1fa21ddc9dde8ddf7a503f64c84cecd7b8 Mon Sep 17 00:00:00 2001 From: Philipp Renoth Date: Wed, 10 Feb 2021 22:39:15 +0100 Subject: [PATCH] segfaulting: DebugUtilsMessengerCallbackDataEXT::pMessageIdName may be null in debug callback (#1487) * vulkano: DebugUtilsMessengerCallbackDataEXT::pMessageIdName may be null in debug callback - https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkDebugUtilsMessengerCallbackDataEXT.html#VUID-VkDebugUtilsMessengerCallbackDataEXT-pMessageIdName-parameter * make `Message::layer_prefix` an Option --- CHANGELOG_VULKANO.md | 1 + examples/src/bin/debug.rs | 5 ++++- vulkano/src/instance/debug.rs | 13 ++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG_VULKANO.md b/CHANGELOG_VULKANO.md index 26891511..7482b5d4 100644 --- a/CHANGELOG_VULKANO.md +++ b/CHANGELOG_VULKANO.md @@ -1,5 +1,6 @@ # Unreleased +- **Breaking** `Message::layer_prefix` turned to Option to prevent segfaults when Vulkan message didn't provide `pMessageIdName` value - **Breaking** On `AutoCommandBufferBuilder`, methods that bind a descriptor set now take a `dynamic_offsets` parameter - **Breaking** On `AutoCommandBufferBuilder` and `SyncCommandBufferBuilder`, the `update_buffer` method now takes `data` by reference - **Breaking** Made `PipelineLayoutDescTweaks` public, for use with compute pipelines diff --git a/examples/src/bin/debug.rs b/examples/src/bin/debug.rs index 20e52b32..45c952d5 100644 --- a/examples/src/bin/debug.rs +++ b/examples/src/bin/debug.rs @@ -99,7 +99,10 @@ fn main() { println!( "{} {} {}: {}", - msg.layer_prefix, ty, severity, msg.description + msg.layer_prefix.unwrap_or("unknown"), + ty, + severity, + msg.description ); }) .ok(); diff --git a/vulkano/src/instance/debug.rs b/vulkano/src/instance/debug.rs index 054df1e1..d7ab40cc 100644 --- a/vulkano/src/instance/debug.rs +++ b/vulkano/src/instance/debug.rs @@ -96,9 +96,12 @@ impl DebugCallback { let user_callback = user_data as *mut Box as *const _; let user_callback: &Box = &*user_callback; - let layer_prefix = CStr::from_ptr((*callback_data).pMessageIdName) - .to_str() - .expect("debug callback message not utf-8"); + let layer_prefix = (*callback_data).pMessageIdName.as_ref().map(|msg_id_name| { + CStr::from_ptr(msg_id_name) + .to_str() + .expect("debug callback message not utf-8") + }); + let description = CStr::from_ptr((*callback_data).pMessage) .to_str() .expect("debug callback message not utf-8"); @@ -231,8 +234,8 @@ pub struct Message<'a> { pub severity: MessageSeverity, /// Type of message, pub ty: MessageType, - /// Prefix of the layer that reported this message. - pub layer_prefix: &'a str, + /// Prefix of the layer that reported this message or `None` if unknown. + pub layer_prefix: Option<&'a str>, /// Description of the message. pub description: &'a str, }