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))
|
.or_else(|_| second_builder.build_windowed(builder, &event_loop))
|
||||||
.map_err(|error| {
|
.map_err(|error| {
|
||||||
use glutin::CreationError;
|
use glutin::CreationError;
|
||||||
|
use iced_graphics::Error as ContextError;
|
||||||
|
|
||||||
match error {
|
match error {
|
||||||
CreationError::Window(error) => {
|
CreationError::Window(error) => {
|
||||||
Error::WindowCreationFailed(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)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum 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")]
|
#[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")]
|
#[error("the application window could not be created")]
|
||||||
WindowCreationFailed(Box<dyn std::error::Error + Send + Sync>),
|
WindowCreationFailed(Box<dyn std::error::Error + Send + Sync>),
|
||||||
|
|
||||||
/// A suitable graphics adapter or device could not be found.
|
/// The application context could not be created.
|
||||||
#[error("a suitable graphics adapter or device could not be found")]
|
#[error("the application context could not be created")]
|
||||||
GraphicsAdapterNotFound,
|
ContextCreationFailed(iced_graphics::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<iced_winit::Error> for Error {
|
impl From<iced_winit::Error> for Error {
|
||||||
|
|
@ -25,8 +25,8 @@ impl From<iced_winit::Error> for Error {
|
||||||
iced_winit::Error::WindowCreationFailed(error) => {
|
iced_winit::Error::WindowCreationFailed(error) => {
|
||||||
Error::WindowCreationFailed(Box::new(error))
|
Error::WindowCreationFailed(Box::new(error))
|
||||||
}
|
}
|
||||||
iced_winit::Error::GraphicsAdapterNotFound => {
|
iced_winit::Error::ContextCreationFailed(error) => {
|
||||||
Error::GraphicsAdapterNotFound
|
Error::ContextCreationFailed(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
settings,
|
settings,
|
||||||
compatible_window,
|
compatible_window,
|
||||||
))
|
))
|
||||||
.ok_or(Error::AdapterNotFound)?;
|
.ok_or(Error::GraphicsAdapterNotFound)?;
|
||||||
|
|
||||||
let backend = compositor.create_backend();
|
let backend = compositor.create_backend();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,13 @@ pub enum Error {
|
||||||
#[error("the application window could not be created")]
|
#[error("the application window could not be created")]
|
||||||
WindowCreationFailed(winit::error::OsError),
|
WindowCreationFailed(winit::error::OsError),
|
||||||
|
|
||||||
/// A suitable graphics adapter or device could not be found.
|
/// The application context could not be created.
|
||||||
#[error("a suitable graphics adapter or device could not be found")]
|
#[error("the application context could not be created")]
|
||||||
GraphicsAdapterNotFound,
|
ContextCreationFailed(iced_graphics::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<iced_graphics::Error> for Error {
|
impl From<iced_graphics::Error> for Error {
|
||||||
fn from(error: iced_graphics::Error) -> Error {
|
fn from(error: iced_graphics::Error) -> Error {
|
||||||
match error {
|
Error::ContextCreationFailed(error)
|
||||||
iced_graphics::Error::AdapterNotFound => {
|
|
||||||
Error::GraphicsAdapterNotFound
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue