Skip to content

Commit

Permalink
Guard against invalid resizes on macOS-14
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 28, 2024
1 parent 552a571 commit e938e10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
23 changes: 14 additions & 9 deletions bin/boilerplate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![allow(clippy::single_match)]
use vangers::{
config::{settings::Terrain, Settings},
config::Settings,
render::{GraphicsContext, ScreenTargets, DEPTH_FORMAT},
};

use futures::executor::LocalPool;
use log::info;
use winit::{
event,
event_loop::{ControlFlow, EventLoop},
Expand Down Expand Up @@ -42,23 +41,22 @@ pub struct Harness {

pub struct HarnessOptions {
pub title: &'static str,
pub uses_level: bool,
}

impl Harness {
pub fn init(options: HarnessOptions) -> (Self, Settings) {
env_logger::init();
let mut task_pool = LocalPool::new();

info!("Loading the settings");
log::info!("Loading the settings");
let settings = Settings::load("config/settings.ron");
let extent = wgpu::Extent3d {
width: settings.window.size[0],
height: settings.window.size[1],
depth_or_array_layers: 1,
};

info!("Initializing the window");
log::info!("Initializing the window");
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: settings.backend.to_wgpu(),
..Default::default()
Expand All @@ -73,7 +71,7 @@ impl Harness {
let surface =
unsafe { instance.create_surface(&window) }.expect("Unable to create surface.");

info!("Initializing the device");
log::info!("Initializing the device");
let adapter = task_pool
.run_until(instance.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
Expand Down Expand Up @@ -201,8 +199,9 @@ impl Harness {
event::Event::WindowEvent {
event: event::WindowEvent::Resized(size),
..
} => {
info!("Resizing to {:?}", size);
} if size.width != !0 => {
//Note: on macOS 14 this can happen ^
log::info!("Resizing to {:?}", size);
gfx.screen_size = wgpu::Extent3d {
width: size.width,
height: size.height,
Expand Down Expand Up @@ -233,12 +232,18 @@ impl Harness {
.create_view(&wgpu::TextureViewDescriptor::default());
app.resize(&gfx.device, gfx.screen_size);
}
event::Event::WindowEvent {
event: event::WindowEvent::Resized(size),
..
} => {
log::warn!("Ignoring invalid resize request: {:?}", size)
}
event::Event::WindowEvent { event, .. } => match event {
event::WindowEvent::Focused(false) => {
needs_reload = win.reload_on_focus;
}
event::WindowEvent::Focused(true) if needs_reload => {
info!("Reloading shaders");
log::info!("Reloading shaders");
app.reload(&gfx.device);
needs_reload = false;
}
Expand Down
6 changes: 2 additions & 4 deletions bin/level/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ mod boilerplate;
fn main() {
use std::env;

let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions {
title: "level",
uses_level: true,
});
let (harness, settings) =
boilerplate::Harness::init(boilerplate::HarnessOptions { title: "level" });

let args: Vec<_> = env::args().collect();
let mut options = getopts::Options::new();
Expand Down
6 changes: 2 additions & 4 deletions bin/model/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ mod boilerplate;
fn main() {
use std::env;

let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions {
title: "model",
uses_level: false,
});
let (harness, settings) =
boilerplate::Harness::init(boilerplate::HarnessOptions { title: "model" });

let args: Vec<_> = env::args().collect();
let mut options = getopts::Options::new();
Expand Down
6 changes: 2 additions & 4 deletions bin/road/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ mod physics;
fn main() {
use std::env;

let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions {
title: "road",
uses_level: true,
});
let (harness, settings) =
boilerplate::Harness::init(boilerplate::HarnessOptions { title: "road" });

info!("Parsing command line");
let args: Vec<_> = env::args().collect();
Expand Down

0 comments on commit e938e10

Please sign in to comment.