[rs] Add Device::on_captured_error

The implementation is dummy one
This commit is contained in:
Mikko Lehtonen
2020-09-03 09:22:58 +03:00
parent 117d323f71
commit f987a82503
3 changed files with 50 additions and 0 deletions

View File

@@ -930,6 +930,14 @@ impl crate::Context for Context {
.unwrap_pretty()
}
fn device_on_uncaptured_error(
&self,
_device: &Self::DeviceId,
_handler: impl crate::UncapturedErrorHandler,
) {
todo!();
}
fn buffer_map_async(
&self,
buffer: &Self::BufferId,

View File

@@ -1148,6 +1148,14 @@ impl crate::Context for Context {
// Device is polled automatically
}
fn device_on_uncaptured_error(
&self,
_device: &Self::DeviceId,
_handler: impl crate::UncapturedErrorHandler,
) {
// TODO:
}
fn buffer_map_async(
&self,
_buffer: &Self::BufferId,

View File

@@ -262,6 +262,11 @@ trait Context: Debug + Send + Sized + Sync {
) -> Self::RenderBundleEncoderId;
fn device_drop(&self, device: &Self::DeviceId);
fn device_poll(&self, device: &Self::DeviceId, maintain: Maintain);
fn device_on_uncaptured_error(
&self,
device: &Self::DeviceId,
handler: impl UncapturedErrorHandler,
);
fn buffer_map_async(
&self,
@@ -1542,6 +1547,11 @@ impl Device {
id: Context::device_create_swap_chain(&*self.context, &self.id, &surface.id, desc),
}
}
/// Set a callback for errors that are not handled in error scopes.
pub fn on_uncaptured_error(&self, handler: impl UncapturedErrorHandler) {
self.context.device_on_uncaptured_error(&self.id, handler);
}
}
impl Drop for Device {
@@ -2610,3 +2620,27 @@ impl SwapChain {
}
}
}
/// Type for the callback of uncaptured error handler
pub trait UncapturedErrorHandler: Fn(Error) + Send + Sync + 'static {}
impl<T> UncapturedErrorHandler for T where T: Fn(Error) + Send + Sync + 'static {}
/// Error type
#[derive(Debug)]
pub enum Error {
/// Out of memory error
OutOfMemoryError,
/// Validation error, signifying a bug in code or data
ValidationError {
///
source: Box<dyn error::Error + Send + Sync + 'static>,
},
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::OutOfMemoryError => f.write_str("Out of Memory"),
Error::ValidationError { source } => std::fmt::Display::fmt(source, f),
}
}
}