Skip to content

Commit

Permalink
Bug 1791881 - Don't crash in buffer_destroy if the buffer is in an in…
Browse files Browse the repository at this point in the history
…valid state. r=jgilbert

Once gfx-rs/wgpu#3094 is merged, unallocated and freed handles will panic in wgpu-core so we don't have to do it here. In the mean time it will produce the wrong error but still fail safely. DestroyError::Invalid means the handle exists but is not is in an invalid state, for example if the buffer was created with invalid parameter like in this bug's test case.

Differential Revision: https://phabricator.services.mozilla.com/D159054
  • Loading branch information
nical committed Oct 13, 2022
1 parent e492626 commit f8a2ef4
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions gfx/wgpu_bindings/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,10 @@ pub extern "C" fn wgpu_server_buffer_unmap(

#[no_mangle]
pub extern "C" fn wgpu_server_buffer_destroy(global: &Global, self_id: id::BufferId) {
use wgc::resource::DestroyError;
match gfx_select!(self_id => global.buffer_destroy(self_id)) {
Err(DestroyError::Invalid) => {
// This indicates an error on our side.
panic!("Buffer already dropped.");
}
_ => {
// Other error need to be reported but are not fatal, since users
// can, for example, ask for a buffer to be destroyed multiple times.
}
}
// Per spec, there is no need for the buffer or even device to be in a valid state,
// even calling calling destroy multiple times is fine, so no error to push into
// an error scope.
let _ = gfx_select!(self_id => global.buffer_destroy(self_id));
}

#[no_mangle]
Expand Down

0 comments on commit f8a2ef4

Please sign in to comment.