mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Merge #566
566: Report out of memory errors r=kvark a=scoopr Co-authored-by: Mikko Lehtonen <scoopr@iki.fi>
This commit is contained in:
@@ -1463,6 +1463,25 @@ where
|
||||
fn unwrap_error_sink(self, error_sink: &ErrorSink, fallback: impl FnOnce() -> T) -> T {
|
||||
self.unwrap_or_else(|err| {
|
||||
let error_sink = error_sink.lock();
|
||||
|
||||
// Check to see if it is a out of memory error
|
||||
let mut source_opt: Option<&(dyn std::error::Error + 'static)> = Some(&err);
|
||||
while let Some(source) = source_opt {
|
||||
if let Some(device_error) = source.downcast_ref::<wgc::device::DeviceError>() {
|
||||
match device_error {
|
||||
wgc::device::DeviceError::OutOfMemory => {
|
||||
error_sink.handle_error(crate::Error::OutOfMemoryError {
|
||||
source: Box::new(err)
|
||||
});
|
||||
return fallback();
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
source_opt = source.source();
|
||||
}
|
||||
|
||||
// Otherwise, it is a validation error
|
||||
error_sink.handle_error(crate::Error::ValidationError {
|
||||
source: Box::new(err),
|
||||
});
|
||||
|
||||
@@ -2633,7 +2633,10 @@ impl<T> UncapturedErrorHandler for T where T: Fn(Error) + Send + Sync + 'static
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Out of memory error
|
||||
OutOfMemoryError,
|
||||
OutOfMemoryError {
|
||||
///
|
||||
source: Box<dyn error::Error + Send + Sync + 'static>,
|
||||
},
|
||||
/// Validation error, signifying a bug in code or data
|
||||
ValidationError {
|
||||
///
|
||||
@@ -2644,7 +2647,7 @@ pub enum Error {
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
Error::OutOfMemoryError => None,
|
||||
Error::OutOfMemoryError { source } => Some(source.as_ref()),
|
||||
Error::ValidationError { source } => Some(source.as_ref()),
|
||||
}
|
||||
}
|
||||
@@ -2653,7 +2656,7 @@ impl error::Error for Error {
|
||||
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::OutOfMemoryError { .. } => f.write_str("Out of Memory"),
|
||||
Error::ValidationError { .. } => f.write_str("Validation error"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user