Skip to content

Commit f326782

Browse files
GetBindGroupLayout 'raises error' instead of panicing on invalid index (#320) (#321)
Co-authored-by: Almar Klein <[email protected]>
1 parent 118848f commit f326782

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/lib.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub struct WGPUComputePassEncoderImpl {
147147
pub struct WGPUComputePipelineImpl {
148148
context: Arc<Context>,
149149
id: id::ComputePipelineId,
150+
error_sink: ErrorSink,
150151
}
151152
impl Drop for WGPUComputePipelineImpl {
152153
fn drop(&mut self) {
@@ -245,6 +246,7 @@ pub struct WGPURenderPassEncoderImpl {
245246
pub struct WGPURenderPipelineImpl {
246247
context: Arc<Context>,
247248
id: id::RenderPipelineId,
249+
error_sink: ErrorSink,
248250
}
249251
impl Drop for WGPURenderPipelineImpl {
250252
fn drop(&mut self) {
@@ -1680,17 +1682,21 @@ pub unsafe extern "C" fn wgpuComputePipelineGetBindGroupLayout(
16801682
pipeline: native::WGPUComputePipeline,
16811683
group_index: u32,
16821684
) -> native::WGPUBindGroupLayout {
1683-
let (pipeline_id, context) = {
1685+
let (pipeline_id, context, error_sink) = {
16841686
let pipeline = pipeline.as_ref().expect("invalid pipeline");
1685-
(pipeline.id, &pipeline.context)
1687+
(pipeline.id, &pipeline.context, &pipeline.error_sink)
16861688
};
16871689

16881690
let (bind_group_layout_id, error) = gfx_select!(pipeline_id => context.compute_pipeline_get_bind_group_layout(pipeline_id, group_index, ()));
16891691
if let Some(cause) = error {
1690-
panic!(
1691-
"Error in wgpuComputePipelineGetBindGroupLayout: Error reflecting bind group {group_index}: {f}",
1692-
f = format_error(context, &cause)
1693-
);
1692+
handle_error(
1693+
context,
1694+
error_sink,
1695+
cause,
1696+
"",
1697+
None,
1698+
"wgpuComputePipelineGetBindGroupLayout",
1699+
)
16941700
}
16951701

16961702
Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl {
@@ -1945,6 +1951,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateComputePipeline(
19451951
Arc::into_raw(Arc::new(WGPUComputePipelineImpl {
19461952
context: context.clone(),
19471953
id: compute_pipeline_id,
1954+
error_sink: error_sink.clone(),
19481955
}))
19491956
}
19501957

@@ -2227,6 +2234,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateRenderPipeline(
22272234
Arc::into_raw(Arc::new(WGPURenderPipelineImpl {
22282235
context: context.clone(),
22292236
id: render_pipeline_id,
2237+
error_sink: error_sink.clone(),
22302238
}))
22312239
}
22322240

@@ -3500,17 +3508,24 @@ pub unsafe extern "C" fn wgpuRenderPipelineGetBindGroupLayout(
35003508
render_pipeline: native::WGPURenderPipeline,
35013509
group_index: u32,
35023510
) -> native::WGPUBindGroupLayout {
3503-
let (render_pipeline_id, context) = {
3511+
let (render_pipeline_id, context, error_sink) = {
35043512
let render_pipeline = render_pipeline.as_ref().expect("invalid render pipeline");
3505-
(render_pipeline.id, &render_pipeline.context)
3513+
(
3514+
render_pipeline.id,
3515+
&render_pipeline.context,
3516+
&render_pipeline.error_sink,
3517+
)
35063518
};
3507-
35083519
let (bind_group_layout_id, error) = gfx_select!(render_pipeline_id => context.render_pipeline_get_bind_group_layout(render_pipeline_id, group_index, ()));
35093520
if let Some(cause) = error {
3510-
panic!(
3511-
"Error in wgpuRenderPipelineGetBindGroupLayout: Error reflecting bind group {group_index}: {f}",
3512-
f = format_error(context, &cause)
3513-
);
3521+
handle_error(
3522+
context,
3523+
error_sink,
3524+
cause,
3525+
"",
3526+
None,
3527+
"wgpuRenderPipelineGetBindGroupLayout",
3528+
)
35143529
}
35153530

35163531
Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl {

0 commit comments

Comments
 (0)