Skip to content

Commit

Permalink
Fixing panic when window is 0-sized
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Dec 22, 2023
1 parent 421cbfb commit 7a3861a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
instance between windows.
- Each `Window` frame now waits until it's fully rendered before yielding back
to the windqow loop.
- When a `Window` has a 0 dimension, it will no longer try to redraw. This
presented as a panic when a window was minimized.

## v0.6.1 (2023-12-19)

Expand Down
32 changes: 18 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,16 +969,18 @@ where
}

fn redraw(&mut self, window: &mut RunningWindow<AppEvent<User>>) {
let Some(surface) = self.current_surface_texture(window) else {
return;
};
if self.config.width > 0 && self.config.height > 0 {
let Some(surface) = self.current_surface_texture(window) else {
return;
};

let render_start = Instant::now();
let render_start = Instant::now();

self.render_to_surface(surface, render_start, window);
self.render_to_surface(surface, render_start, window);

self.last_render_duration = render_start.elapsed();
self.last_render = render_start;
self.last_render_duration = render_start.elapsed();
self.last_render = render_start;
}
}

fn close_requested(&mut self, window: &mut RunningWindow<AppEvent<User>>) -> bool {
Expand Down Expand Up @@ -1017,13 +1019,15 @@ where
fn resized(&mut self, window: &mut RunningWindow<AppEvent<User>>) {
self.config.width = window.inner_size().width;
self.config.height = window.inner_size().height;
self.surface.configure(&self.device, &self.config);
self.kludgine.resize(
window.inner_size().into(),
window.scale().cast::<f32>(),
&self.queue,
);
window.set_needs_redraw();
if self.config.width > 0 && self.config.height > 0 {
self.surface.configure(&self.device, &self.config);
self.kludgine.resize(
window.inner_size().into(),
window.scale().cast::<f32>(),
&self.queue,
);
window.set_needs_redraw();
}
self.behavior.resized(
Window::new(
window,
Expand Down

0 comments on commit 7a3861a

Please sign in to comment.