Skip to content

Commit 5568e83

Browse files
committed
app: Correct invalid window size, reject window resize events if the window is minimized
1 parent c00d1ad commit 5568e83

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
9292
- When a texture handle is explicitly set to `none`, Alkahest will now properly unset the texture instead of binding the fallback texture
9393
- Bake rustc version as a constant instead of checking it at runtime
9494
- Fixed solid geometry not rendering in simpler maps (Shard, Sunken, etc.)
95+
- Fixed invalid window sizes being handled (eg. win32 resizes the window to 0x0 when minimizing it)
9596

9697
## 0.5.0 - 2024-07-24
9798

crates/alkahest/src/app.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl AlkahestApp {
8686

8787
let window = winit::window::WindowBuilder::new()
8888
.with_title("Alkahest")
89-
.with_min_inner_size(PhysicalSize::new(640, 360))
89+
.with_min_inner_size(PhysicalSize::new(1280, 720))
9090
.with_inner_size(config::with(|c| {
9191
PhysicalSize::new(c.window.width, c.window.height)
9292
}))
@@ -104,6 +104,14 @@ impl AlkahestApp {
104104
.unwrap();
105105
let window = Arc::new(window);
106106

107+
// Make sure the window size in the config is not below the minimum size
108+
config::with_mut(|c| {
109+
let corrected_size = window.inner_size();
110+
c.window.width = corrected_size.width;
111+
c.window.height = corrected_size.height;
112+
});
113+
config::try_persist().ok();
114+
107115
puffin::set_scopes_on(cfg!(feature = "profiler"));
108116

109117
let gctx = Arc::new(GpuContext::create(&window).unwrap());
@@ -274,27 +282,31 @@ impl AlkahestApp {
274282
}
275283
}
276284
WindowEvent::Resized(new_dims) => {
277-
if let Some(swap_chain) = gctx.swap_chain.as_ref() {
278-
let _ = gui.renderer.as_mut().map(|renderer| {
279-
let _ = renderer
280-
.resize_buffers(swap_chain, || {
281-
gctx.resize_swapchain(new_dims.width, new_dims.height);
282-
HRESULT(0)
283-
})
284-
.unwrap();
285-
});
286-
}
285+
let minimized = window.is_minimized().unwrap_or(false);
286+
if !minimized && new_dims.width > 0 && new_dims.height > 0 {
287+
if let Some(swap_chain) = gctx.swap_chain.as_ref() {
288+
let _ = gui.renderer.as_mut().map(|renderer| {
289+
let _ = renderer
290+
.resize_buffers(swap_chain, || {
291+
gctx.resize_swapchain(new_dims.width, new_dims.height);
292+
HRESULT(0)
293+
})
294+
.unwrap();
295+
});
296+
}
287297

288-
renderer.resize_buffers(new_dims.width, new_dims.height);
298+
renderer.resize_buffers(new_dims.width, new_dims.height);
289299

290-
resources.get_mut::<Camera>().set_viewport(Viewport {
291-
size: glam::UVec2::new(new_dims.width, new_dims.height),
292-
origin: glam::UVec2::ZERO,
293-
});
300+
resources.get_mut::<Camera>().set_viewport(Viewport {
301+
size: glam::UVec2::new(new_dims.width, new_dims.height),
302+
origin: glam::UVec2::ZERO,
303+
});
294304

295-
config::with_mut(|c| {
296-
(c.window.width, c.window.height) = (new_dims.width, new_dims.height)
297-
});
305+
config::with_mut(|c| {
306+
(c.window.width, c.window.height) =
307+
(new_dims.width, new_dims.height)
308+
});
309+
}
298310
}
299311
WindowEvent::RedrawRequested => {
300312
if *next_config_save < std::time::Instant::now() {

0 commit comments

Comments
 (0)