diff --git a/NoiseEngine.Native/src/errors/mod.rs b/NoiseEngine.Native/src/errors/mod.rs index a1f61ce8..d2fe1528 100644 --- a/NoiseEngine.Native/src/errors/mod.rs +++ b/NoiseEngine.Native/src/errors/mod.rs @@ -4,3 +4,4 @@ pub mod conversions; pub mod invalid_operation; pub mod null_reference; pub mod overflow; +pub mod platform_not_supported; diff --git a/NoiseEngine.Native/src/errors/platform_not_supported.rs b/NoiseEngine.Native/src/errors/platform_not_supported.rs new file mode 100644 index 00000000..ea899092 --- /dev/null +++ b/NoiseEngine.Native/src/errors/platform_not_supported.rs @@ -0,0 +1,44 @@ +use std::{error::Error, fmt::Display}; + +use crate::interop::prelude::{ResultError, ResultErrorKind}; + +#[derive(Debug)] +pub struct PlatformNotSupportedError { + message: String, +} + +impl PlatformNotSupportedError { + pub fn new(message: String) -> Self { + Self { message } + } + + pub fn with_str(message: &str) -> Self { + Self::new(message.to_owned()) + } +} + +impl Default for PlatformNotSupportedError { + fn default() -> Self { + Self { + message: "Platform not supported.".to_string(), + } + } +} + +impl Error for PlatformNotSupportedError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } +} + +impl Display for PlatformNotSupportedError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.message) + } +} + +impl From for ResultError { + fn from(err: PlatformNotSupportedError) -> Self { + ResultError::with_kind(&err, ResultErrorKind::PlatformNotSupported) + } +} diff --git a/NoiseEngine.Native/src/interop/rendering/presentation/window_interop.rs b/NoiseEngine.Native/src/interop/rendering/presentation/window_interop.rs index 0371d511..03c800f4 100644 --- a/NoiseEngine.Native/src/interop/rendering/presentation/window_interop.rs +++ b/NoiseEngine.Native/src/interop/rendering/presentation/window_interop.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use cgmath::Vector2; use crate::{ - errors::invalid_operation::InvalidOperationError, + errors::platform_not_supported::PlatformNotSupportedError, interop::prelude::{InteropOption, InteropResult, InteropString}, rendering::presentation::{input::InputData, window::Window, window_settings::WindowSettings}, }; @@ -31,7 +31,7 @@ extern "C" fn rendering_presentation_window_interop_create( #[allow(unreachable_code)] InteropResult::with_err( - InvalidOperationError::with_str("Window is not supported on this device.").into(), + PlatformNotSupportedError::with_str("Window is not supported on this device.").into(), ) } diff --git a/NoiseEngine.Native/src/interop/result_error_kind.rs b/NoiseEngine.Native/src/interop/result_error_kind.rs index 91001389..a2a91a73 100644 --- a/NoiseEngine.Native/src/interop/result_error_kind.rs +++ b/NoiseEngine.Native/src/interop/result_error_kind.rs @@ -8,6 +8,7 @@ pub enum ResultErrorKind { InvalidOperation = 3, Overflow = 4, Argument = 5, + PlatformNotSupported = 6, GraphicsUniversal = 1000, GraphicsInstanceCreate = 1001, diff --git a/NoiseEngine/Interop/ResultError.cs b/NoiseEngine/Interop/ResultError.cs index 20d985c1..640ddf39 100644 --- a/NoiseEngine/Interop/ResultError.cs +++ b/NoiseEngine/Interop/ResultError.cs @@ -49,6 +49,7 @@ internal struct ResultError : IDisposable { ResultErrorKind.InvalidOperation => new InvalidOperationException(Message, innerException), ResultErrorKind.Overflow => new OverflowException(Message, innerException), ResultErrorKind.Argument => new ArgumentException(Message, innerException), + ResultErrorKind.PlatformNotSupported => new PlatformNotSupportedException(Message, innerException), ResultErrorKind.GraphicsUniversal => new GraphicsException(Message, innerException), ResultErrorKind.GraphicsInstanceCreate => new GraphicsInstanceCreateException(Message, innerException), diff --git a/NoiseEngine/Interop/ResultErrorKind.cs b/NoiseEngine/Interop/ResultErrorKind.cs index 0838bd95..b17a602b 100644 --- a/NoiseEngine/Interop/ResultErrorKind.cs +++ b/NoiseEngine/Interop/ResultErrorKind.cs @@ -7,6 +7,7 @@ internal enum ResultErrorKind : uint { InvalidOperation = 3, Overflow = 4, Argument = 5, + PlatformNotSupported = 6, GraphicsUniversal = 1000, GraphicsInstanceCreate = 1001,