Fix crash when window gets minimized (#332). Fixes #275

* Make sure aspect ratio is always valid

* Do not render while window has an invalid size (e.g. window is minimized)
This commit is contained in:
Mèir Noordermeer 2020-06-21 12:24:41 +02:00 committed by GitHub
parent 0dd21a0a20
commit b26500e1b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -352,6 +352,11 @@ fn main2() {
game.tick(delta);
game.server.tick(&mut game.renderer, delta);
// Check if window is valid, it might be minimized
if physical_width == 0 || physical_height == 0 {
return;
}
game.renderer.update_camera(physical_width, physical_height);
game.server.world.compute_render_list(&mut game.renderer);
game.chunk_builder.tick(&mut game.server.world, &mut game.renderer, version);
@ -364,7 +369,6 @@ fn main2() {
ui_container.tick(&mut game.renderer, delta, width as f64, height as f64);
game.renderer.tick(&mut game.server.world, delta, width, height, physical_width, physical_height);
if fps_cap > 0 && !vsync {
let frame_time = now.elapsed();
let sleep_interval = Duration::from_millis(1000 / fps_cap as u64);

View File

@ -259,10 +259,13 @@ impl Renderer {
self.height = height;
gl::viewport(0, 0, width as i32, height as i32);
let fovy = cgmath::Rad::from(cgmath::Deg(90.0_f32));
let aspect = (width as f32 / height as f32).max(1.0);
self.perspective_matrix = cgmath::Matrix4::from(
cgmath::PerspectiveFov {
fovy: cgmath::Rad::from(cgmath::Deg(90f32)),
aspect: (width as f32 / height as f32),
fovy,
aspect,
near: 0.1f32,
far: 500.0f32,
}