Change uncaptured error handler pointer type from Box to Arc.

This will be necessary for the next change.
This commit is contained in:
Kevin Reid 2025-07-26 09:35:31 -07:00 committed by Connor Fitzgerald
parent 2e8a600e35
commit ea8315e28e
6 changed files with 9 additions and 8 deletions

View File

@ -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. - 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 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 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). By @kpreid in [#8011](https://github.com/gfx-rs/wgpu/pull/8011).
#### Naga #### Naga

View File

@ -240,7 +240,7 @@ impl DeviceInterface for CustomDevice {
unimplemented!() unimplemented!()
} }
fn on_uncaptured_error(&self, _handler: Box<dyn wgpu::UncapturedErrorHandler>) { fn on_uncaptured_error(&self, _handler: Arc<dyn wgpu::UncapturedErrorHandler>) {
unimplemented!() unimplemented!()
} }

View File

@ -407,8 +407,8 @@ impl Device {
QuerySet { inner: query_set } QuerySet { inner: query_set }
} }
/// Set a callback for errors that are not handled in error scopes. /// Set a callback which will be called for all errors that are not handled in error scopes.
pub fn on_uncaptured_error(&self, handler: Box<dyn UncapturedErrorHandler>) { pub fn on_uncaptured_error(&self, handler: Arc<dyn UncapturedErrorHandler>) {
self.inner.on_uncaptured_error(handler) self.inner.on_uncaptured_error(handler)
} }

View File

@ -10,6 +10,7 @@ use alloc::{
format, format,
rc::Rc, rc::Rc,
string::{String, ToString as _}, string::{String, ToString as _},
sync::Arc,
vec, vec,
vec::Vec, vec::Vec,
}; };
@ -2409,7 +2410,7 @@ impl dispatch::DeviceInterface for WebDevice {
closure.forget(); closure.forget();
} }
fn on_uncaptured_error(&self, handler: Box<dyn crate::UncapturedErrorHandler>) { fn on_uncaptured_error(&self, handler: Arc<dyn crate::UncapturedErrorHandler>) {
let f = Closure::wrap(Box::new(move |event: webgpu_sys::GpuUncapturedErrorEvent| { let f = Closure::wrap(Box::new(move |event: webgpu_sys::GpuUncapturedErrorEvent| {
let error = crate::Error::from_js(event.error().value_of()); let error = crate::Error::from_js(event.error().value_of());
handler(error); handler(error);

View File

@ -617,7 +617,7 @@ struct ErrorScope {
struct ErrorSinkRaw { struct ErrorSinkRaw {
scopes: Vec<ErrorScope>, scopes: Vec<ErrorScope>,
uncaptured_handler: Option<Box<dyn crate::UncapturedErrorHandler>>, uncaptured_handler: Option<Arc<dyn crate::UncapturedErrorHandler>>,
} }
impl ErrorSinkRaw { impl ErrorSinkRaw {
@ -1757,7 +1757,7 @@ impl dispatch::DeviceInterface for CoreDevice {
.device_set_device_lost_closure(self.id, device_lost_callback); .device_set_device_lost_closure(self.id, device_lost_callback);
} }
fn on_uncaptured_error(&self, handler: Box<dyn crate::UncapturedErrorHandler>) { fn on_uncaptured_error(&self, handler: Arc<dyn crate::UncapturedErrorHandler>) {
let mut error_sink = self.error_sink.lock(); let mut error_sink = self.error_sink.lock();
error_sink.uncaptured_handler = Some(handler); error_sink.uncaptured_handler = Some(handler);
} }

View File

@ -185,7 +185,7 @@ pub trait DeviceInterface: CommonTraits {
fn set_device_lost_callback(&self, device_lost_callback: BoxDeviceLostCallback); fn set_device_lost_callback(&self, device_lost_callback: BoxDeviceLostCallback);
fn on_uncaptured_error(&self, handler: Box<dyn crate::UncapturedErrorHandler>); fn on_uncaptured_error(&self, handler: Arc<dyn crate::UncapturedErrorHandler>);
fn push_error_scope(&self, filter: crate::ErrorFilter); fn push_error_scope(&self, filter: crate::ErrorFilter);
fn pop_error_scope(&self) -> Pin<Box<dyn PopErrorScopeFuture>>; fn pop_error_scope(&self) -> Pin<Box<dyn PopErrorScopeFuture>>;