Skip to content

Commit

Permalink
Improve error handling in Window::new
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed May 25, 2022
1 parent 500110d commit 9e09adc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Renderer {
///
/// // Create window
/// let event_loop = winit::event_loop::EventLoop::new();
/// let window = window::Window::new(&event_loop);
/// let window = window::Window::new(&event_loop).unwrap();
///
/// // Attach renderer to the window
/// let mut renderer = graphics::Renderer::new(&window);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn run(
shape_processor: ShapeProcessor,
) -> Result<(), graphics::InitError> {
let event_loop = EventLoop::new();
let window = Window::new(&event_loop);
let window = Window::new(&event_loop).unwrap();

let mut previous_time = Instant::now();

Expand Down
12 changes: 8 additions & 4 deletions crates/fj-viewer/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ impl Window {
/// let event_loop = winit::event_loop::EventLoop::new();
/// let window = fj_viewer::window::Window::new(&event_loop);
/// ```
pub fn new(event_loop: &EventLoop<()>) -> Self {
pub fn new(event_loop: &EventLoop<()>) -> Result<Self, Error> {
let window = WindowBuilder::new()
.with_title("Fornjot")
.with_maximized(true)
.with_decorations(true)
.with_transparent(false)
.build(event_loop)
.unwrap();
.build(event_loop)?;

Self(window)
Ok(Self(window))
}

/// Returns a shared reference to the wrapped window
Expand All @@ -40,3 +39,8 @@ impl Window {
self.0.inner_size().height
}
}

/// Error initializing window
#[derive(Debug, thiserror::Error)]
#[error("Error initializing window")]
pub struct Error(#[from] pub winit::error::OsError);

0 comments on commit 9e09adc

Please sign in to comment.