fix(app): changed mainloop to mitigate no response from application

This commit is contained in:
lisk77 2025-11-17 22:29:44 +01:00
parent 90e514f642
commit 1a463770a3

View file

@ -370,15 +370,9 @@ impl App {
WindowEvent::CloseRequested {} => elwt.exit(), WindowEvent::CloseRequested {} => elwt.exit(),
WindowEvent::Focused(focused) => { WindowEvent::Focused(focused) => {
window_focused = *focused; window_focused = *focused;
if window_focused && !window_occluded {
window.request_redraw();
}
} }
WindowEvent::Occluded(occluded) => { WindowEvent::Occluded(occluded) => {
window_occluded = *occluded; window_occluded = *occluded;
if window_focused && !window_occluded {
window.request_redraw();
}
} }
WindowEvent::Resized(physical_size) => { WindowEvent::Resized(physical_size) => {
renderer.resize(*physical_size); renderer.resize(*physical_size);
@ -410,7 +404,6 @@ impl App {
_ => {} _ => {}
}, },
Event::AboutToWait => { Event::AboutToWait => {
elwt.set_control_flow(ControlFlow::Poll);
self.delta_time = renderer.update(); self.delta_time = renderer.update();
if self.dt() != f32::INFINITY { if self.dt() != f32::INFINITY {
@ -425,6 +418,14 @@ impl App {
if window_focused && !window_occluded { if window_focused && !window_occluded {
window.request_redraw(); window.request_redraw();
} }
if self.dt().is_finite() {
let next_frame = std::time::Instant::now()
+ std::time::Duration::from_secs_f32(self.update_timer);
elwt.set_control_flow(ControlFlow::WaitUntil(next_frame));
} else {
elwt.set_control_flow(ControlFlow::Wait);
}
} }
_ => {} _ => {}
} }