Skip to content

Commit

Permalink
GetBindGroupLayout 'raises error' instead of panicing on invalid index
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Nov 22, 2023
1 parent 9105402 commit 30565ef
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub struct WGPURenderPassEncoderImpl {
pub struct WGPURenderPipelineImpl {
context: Arc<Context>,
id: id::RenderPipelineId,
error_sink: ErrorSink,
}
impl Drop for WGPURenderPipelineImpl {
fn drop(&mut self) {
Expand Down Expand Up @@ -2227,6 +2228,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateRenderPipeline(
Arc::into_raw(Arc::new(WGPURenderPipelineImpl {
context: context.clone(),
id: render_pipeline_id,
error_sink: error_sink.clone(),
}))
}

Expand Down Expand Up @@ -3500,17 +3502,13 @@ pub unsafe extern "C" fn wgpuRenderPipelineGetBindGroupLayout(
render_pipeline: native::WGPURenderPipeline,
group_index: u32,
) -> native::WGPUBindGroupLayout {
let (render_pipeline_id, context) = {
let (render_pipeline_id, context, error_sink) = {
let render_pipeline = render_pipeline.as_ref().expect("invalid render pipeline");
(render_pipeline.id, &render_pipeline.context)
(render_pipeline.id, &render_pipeline.context, &render_pipeline.error_sink)
};

let (bind_group_layout_id, error) = gfx_select!(render_pipeline_id => context.render_pipeline_get_bind_group_layout(render_pipeline_id, group_index, ()));
if let Some(cause) = error {
panic!(
"Error in wgpuRenderPipelineGetBindGroupLayout: Error reflecting bind group {group_index}: {f}",
f = format_error(context, &cause)
);
handle_error(context, error_sink, cause, "", None, "wgpuRenderPipelineGetBindGroupLayout")
}

Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl {
Expand Down

0 comments on commit 30565ef

Please sign in to comment.