diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c0a30a74..7d193794c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,7 +72,7 @@ By @Vecvec in [#7913](https://github.com/gfx-rs/wgpu/pull/7913). - Copies of depth/stencil formats must be 4B aligned. - The offset for `set_vertex_buffer` and `set_index_buffer` must be 4B aligned. By @andyleiserson in [#7929](https://github.com/gfx-rs/wgpu/pull/7929). - The offset and size of bindings are validated as fitting within the underlying buffer in more cases. By @andyleiserson in [#7911](https://github.com/gfx-rs/wgpu/pull/7911). -- The function you pass to `Device::on_uncaptured_error()` must now implement `Sync` in addition to `Send`. +- The function you pass to `Device::on_uncaptured_error()` must now implement `Sync` in addition to `Send`, and be wrapped in `Arc` instead of `Box`. By @kpreid in [#8011](https://github.com/gfx-rs/wgpu/pull/8011). #### Naga diff --git a/examples/standalone/custom_backend/src/custom.rs b/examples/standalone/custom_backend/src/custom.rs index 6381c48d1..3082be20b 100644 --- a/examples/standalone/custom_backend/src/custom.rs +++ b/examples/standalone/custom_backend/src/custom.rs @@ -240,7 +240,7 @@ impl DeviceInterface for CustomDevice { unimplemented!() } - fn on_uncaptured_error(&self, _handler: Box) { + fn on_uncaptured_error(&self, _handler: Arc) { unimplemented!() } diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs index 8e0e372dd..a0b51c4be 100644 --- a/wgpu/src/api/device.rs +++ b/wgpu/src/api/device.rs @@ -407,8 +407,8 @@ impl Device { QuerySet { inner: query_set } } - /// Set a callback for errors that are not handled in error scopes. - pub fn on_uncaptured_error(&self, handler: Box) { + /// Set a callback which will be called for all errors that are not handled in error scopes. + pub fn on_uncaptured_error(&self, handler: Arc) { self.inner.on_uncaptured_error(handler) } diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 28fcc99b8..0bd973cdb 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -10,6 +10,7 @@ use alloc::{ format, rc::Rc, string::{String, ToString as _}, + sync::Arc, vec, vec::Vec, }; @@ -2409,7 +2410,7 @@ impl dispatch::DeviceInterface for WebDevice { closure.forget(); } - fn on_uncaptured_error(&self, handler: Box) { + fn on_uncaptured_error(&self, handler: Arc) { let f = Closure::wrap(Box::new(move |event: webgpu_sys::GpuUncapturedErrorEvent| { let error = crate::Error::from_js(event.error().value_of()); handler(error); diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index b97f20870..7cc1a9ecd 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -617,7 +617,7 @@ struct ErrorScope { struct ErrorSinkRaw { scopes: Vec, - uncaptured_handler: Option>, + uncaptured_handler: Option>, } impl ErrorSinkRaw { @@ -1757,7 +1757,7 @@ impl dispatch::DeviceInterface for CoreDevice { .device_set_device_lost_closure(self.id, device_lost_callback); } - fn on_uncaptured_error(&self, handler: Box) { + fn on_uncaptured_error(&self, handler: Arc) { let mut error_sink = self.error_sink.lock(); error_sink.uncaptured_handler = Some(handler); } diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index 3b549a659..0ec87fadd 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -185,7 +185,7 @@ pub trait DeviceInterface: CommonTraits { fn set_device_lost_callback(&self, device_lost_callback: BoxDeviceLostCallback); - fn on_uncaptured_error(&self, handler: Box); + fn on_uncaptured_error(&self, handler: Arc); fn push_error_scope(&self, filter: crate::ErrorFilter); fn pop_error_scope(&self) -> Pin>;