From 12c3c9dd26eccf4fa103bbace858cd56aad335c1 Mon Sep 17 00:00:00 2001 From: Aspen Date: Wed, 6 Mar 2024 15:32:44 -0800 Subject: [PATCH] add null-check for empty arrays in debug trampoline (#2490) --- vulkano/src/instance/debug.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vulkano/src/instance/debug.rs b/vulkano/src/instance/debug.rs index 0c1f5164..50257f27 100644 --- a/vulkano/src/instance/debug.rs +++ b/vulkano/src/instance/debug.rs @@ -340,13 +340,29 @@ pub(super) unsafe extern "system" fn trampoline( message_id_number, message: CStr::from_ptr(p_message).to_str().unwrap(), queue_labels: DebugUtilsMessengerCallbackLabelIter( - slice::from_raw_parts(p_queue_labels, queue_label_count as usize).iter(), + // Some drivers give a null pointer for empty data. + if p_queue_labels.is_null() { + &[] + } else { + slice::from_raw_parts(p_queue_labels, queue_label_count as usize) + } + .iter(), ), cmd_buf_labels: DebugUtilsMessengerCallbackLabelIter( - slice::from_raw_parts(p_cmd_buf_labels, cmd_buf_label_count as usize).iter(), + if p_cmd_buf_labels.is_null() { + &[] + } else { + slice::from_raw_parts(p_cmd_buf_labels, cmd_buf_label_count as usize) + } + .iter(), ), objects: DebugUtilsMessengerCallbackObjectNameInfoIter( - slice::from_raw_parts(p_objects, object_count as usize).iter(), + if p_objects.is_null() { + &[] + } else { + slice::from_raw_parts(p_objects, object_count as usize) + } + .iter(), ), };