Introduce Error::ContextCreationFailed
This commit is contained in:
parent
a33e320521
commit
1e62fdf069
5 changed files with 39 additions and 18 deletions
|
|
@ -80,12 +80,25 @@ where
|
|||
.or_else(|_| second_builder.build_windowed(builder, &event_loop))
|
||||
.map_err(|error| {
|
||||
use glutin::CreationError;
|
||||
use iced_graphics::Error as ContextError;
|
||||
|
||||
match error {
|
||||
CreationError::Window(error) => {
|
||||
Error::WindowCreationFailed(error)
|
||||
}
|
||||
_ => Error::GraphicsAdapterNotFound,
|
||||
CreationError::OpenGlVersionNotSupported => {
|
||||
Error::ContextCreationFailed(
|
||||
ContextError::VersionNotSupported,
|
||||
)
|
||||
}
|
||||
CreationError::NoAvailablePixelFormat => {
|
||||
Error::ContextCreationFailed(
|
||||
ContextError::NoAvailablePixelFormat,
|
||||
)
|
||||
}
|
||||
error => Error::ContextCreationFailed(
|
||||
ContextError::BackendError(error.to_string()),
|
||||
),
|
||||
}
|
||||
})?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,19 @@
|
|||
/// A graphical error that occurred while running an application.
|
||||
/// An error that occurred while creating an application's graphical context.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// A suitable graphics adapter or device could not be found
|
||||
/// The requested backend version is not supported.
|
||||
#[error("the requested backend version is not supported")]
|
||||
VersionNotSupported,
|
||||
|
||||
/// Failed to find any pixel format that matches the criteria.
|
||||
#[error("failed to find any pixel format that matches the criteria")]
|
||||
NoAvailablePixelFormat,
|
||||
|
||||
/// A suitable graphics adapter or device could not be found.
|
||||
#[error("a suitable graphics adapter or device could not be found")]
|
||||
AdapterNotFound,
|
||||
GraphicsAdapterNotFound,
|
||||
|
||||
/// An error occured in the context's internal backend
|
||||
#[error("an error occured in the context's internal backend")]
|
||||
BackendError(String),
|
||||
}
|
||||
|
|
|
|||
10
src/error.rs
10
src/error.rs
|
|
@ -11,9 +11,9 @@ pub enum Error {
|
|||
#[error("the application window could not be created")]
|
||||
WindowCreationFailed(Box<dyn std::error::Error + Send + Sync>),
|
||||
|
||||
/// A suitable graphics adapter or device could not be found.
|
||||
#[error("a suitable graphics adapter or device could not be found")]
|
||||
GraphicsAdapterNotFound,
|
||||
/// The application context could not be created.
|
||||
#[error("the application context could not be created")]
|
||||
ContextCreationFailed(iced_graphics::Error),
|
||||
}
|
||||
|
||||
impl From<iced_winit::Error> for Error {
|
||||
|
|
@ -25,8 +25,8 @@ impl From<iced_winit::Error> for Error {
|
|||
iced_winit::Error::WindowCreationFailed(error) => {
|
||||
Error::WindowCreationFailed(Box::new(error))
|
||||
}
|
||||
iced_winit::Error::GraphicsAdapterNotFound => {
|
||||
Error::GraphicsAdapterNotFound
|
||||
iced_winit::Error::ContextCreationFailed(error) => {
|
||||
Error::ContextCreationFailed(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl iced_graphics::window::Compositor for Compositor {
|
|||
settings,
|
||||
compatible_window,
|
||||
))
|
||||
.ok_or(Error::AdapterNotFound)?;
|
||||
.ok_or(Error::GraphicsAdapterNotFound)?;
|
||||
|
||||
let backend = compositor.create_backend();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,17 +11,13 @@ pub enum Error {
|
|||
#[error("the application window could not be created")]
|
||||
WindowCreationFailed(winit::error::OsError),
|
||||
|
||||
/// A suitable graphics adapter or device could not be found.
|
||||
#[error("a suitable graphics adapter or device could not be found")]
|
||||
GraphicsAdapterNotFound,
|
||||
/// The application context could not be created.
|
||||
#[error("the application context could not be created")]
|
||||
ContextCreationFailed(iced_graphics::Error),
|
||||
}
|
||||
|
||||
impl From<iced_graphics::Error> for Error {
|
||||
fn from(error: iced_graphics::Error) -> Error {
|
||||
match error {
|
||||
iced_graphics::Error::AdapterNotFound => {
|
||||
Error::GraphicsAdapterNotFound
|
||||
}
|
||||
}
|
||||
Error::ContextCreationFailed(error)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue