From 1adb5576cb566432f38b8d8d9891630b94820133 Mon Sep 17 00:00:00 2001 From: Rajveer Malviya Date: Mon, 27 Feb 2023 18:34:13 +0530 Subject: [PATCH] drop cmdbuffer handles in `wgpuQueueSubmitForIndex` (#245) --- src/conv.rs | 2 +- src/device.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/conv.rs b/src/conv.rs index 941ca667..339684c5 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -1011,7 +1011,7 @@ pub fn map_swapchain_descriptor( native::WGPUCompositeAlphaMode_Inherit => wgt::CompositeAlphaMode::Inherit, _ => panic!("invalid alpha mode for swapchain descriptor"), }, - unsafe { make_slice(extras.viewFormats, extras.viewFormatCount as usize) } + unsafe { make_slice(extras.viewFormats, extras.viewFormatCount) } .iter() .map(|f| { map_texture_format(*f).expect("invalid view format for swapchain descriptor") diff --git a/src/device.rs b/src/device.rs index 165d4f23..7c933edb 100644 --- a/src/device.rs +++ b/src/device.rs @@ -695,11 +695,11 @@ pub unsafe extern "C" fn wgpuQueueSubmit( let mut command_buffers = Vec::new(); for command_buffer in make_slice(commands, command_count as usize) { - let ptr = (*command_buffer) as native::WGPUCommandBuffer; - // NOTE: Automaticaly drop the command buffer + let ptr = *command_buffer; if ptr.is_null() { panic!("invalid command buffer"); } + // NOTE: Automaticaly drop the command buffer let buffer_id = Box::from_raw(ptr).id; command_buffers.push(buffer_id) } @@ -718,9 +718,13 @@ pub unsafe extern "C" fn wgpuQueueSubmitForIndex( let mut command_buffers = Vec::new(); for command_buffer in make_slice(commands, command_count as usize) { - let ptr = (*command_buffer) as native::WGPUCommandBuffer; - let (id, _) = ptr.unwrap_handle(); - command_buffers.push(id) + let ptr = *command_buffer; + if ptr.is_null() { + panic!("invalid command buffer"); + } + // NOTE: Automaticaly drop the command buffer + let buffer_id = Box::from_raw(ptr).id; + command_buffers.push(buffer_id) } let submission_index = gfx_select!(queue => context.queue_submit(queue, &command_buffers))