diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index f49c6e39c6..673650d3cd 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -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::() { + 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), }); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 599a7022dc..1c26225c11 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -2633,7 +2633,10 @@ impl UncapturedErrorHandler for T where T: Fn(Error) + Send + Sync + 'static #[derive(Debug)] pub enum Error { /// Out of memory error - OutOfMemoryError, + OutOfMemoryError { + /// + source: Box, + }, /// 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"), } }