Skip to content

Commit a8be8ba

Browse files
committed
Fix duplicate app update and perf bugs
1 parent 578d357 commit a8be8ba

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

crates/bevy_winit/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,21 +518,16 @@ pub fn winit_runner_with(mut app: App) {
518518
.get_resource::<WinitConfig>()
519519
.map_or(ControlFlow::Poll, |config| config.control_flow);
520520
*control_flow = config_control_flow;
521-
if let Some(app_redraw_events) =
522-
app.world.get_resource_mut::<Events<RequestRedraw>>()
523-
{
521+
if let Some(app_redraw_events) = app.world.get_resource::<Events<RequestRedraw>>() {
524522
if redraw_event_reader
525523
.iter(&app_redraw_events)
526-
.next_back()
524+
.last()
527525
.is_some()
528526
{
529527
*control_flow = ControlFlow::Poll;
530-
if !active {
531-
app.update();
532-
}
533528
}
534529
}
535-
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
530+
if let Some(app_exit_events) = app.world.get_resource::<Events<AppExit>>() {
536531
if app_exit_event_reader
537532
.iter(&app_exit_events)
538533
.next_back()

examples/window/low_power.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use bevy::{
1414
/// * While continuously sending `RequestRedraw` events in `Wait` mode: the app will use resources
1515
/// regardless of window state.
1616
///
17-
/// * While in `Poll` mode: the app will update continuously, but will suspend app updates when
18-
/// minimized. Notice resource usage never drops to zero even when minimized.
17+
/// * While in `Poll` mode: the app will update continuously
1918
fn main() {
2019
App::new()
2120
.insert_resource(WinitConfig {
@@ -55,19 +54,19 @@ fn cycle_modes(
5554
TestMode::Wait => TestMode::WaitAndRedraw,
5655
TestMode::WaitAndRedraw => TestMode::Poll,
5756
TestMode::Poll => TestMode::Wait,
57+
};
58+
winit_config.control_flow = match *mode {
59+
TestMode::Wait => ControlFlow::Wait,
60+
TestMode::WaitAndRedraw => ControlFlow::Wait,
61+
TestMode::Poll => ControlFlow::Poll,
5862
}
5963
}
60-
winit_config.control_flow = match *mode {
61-
TestMode::Wait => ControlFlow::Wait,
62-
TestMode::WaitAndRedraw => {
63-
// Sending a `RequestRedraw` event is useful when you want the app to update again
64-
// regardless of any user input. For example, your application might use `ControlFlow::Wait`
65-
// to reduce power use, but UI animations need to play even when there are no inputs, so you
66-
// send redraw requests while the animation is playing.
67-
event.send(RequestRedraw);
68-
ControlFlow::Wait
69-
}
70-
TestMode::Poll => ControlFlow::Poll,
64+
if let TestMode::WaitAndRedraw = *mode {
65+
// Sending a `RequestRedraw` event is useful when you want the app to update again
66+
// regardless of any user input. For example, your application might use `ControlFlow::Wait`
67+
// to reduce power use, but UI animations need to play even when there are no inputs, so you
68+
// send redraw requests while the animation is playing.
69+
event.send(RequestRedraw);
7170
}
7271
}
7372

@@ -82,7 +81,7 @@ pub(crate) mod test_setup {
8281
/// Rotate the cube to make it clear when the app is updating
8382
pub(crate) fn rotate(mut cube_transform: Query<&mut Transform, With<Rotator>>) {
8483
for mut transform in cube_transform.iter_mut() {
85-
transform.rotate(Quat::from_rotation_x(0.05));
84+
transform.rotate(Quat::from_rotation_x(0.04));
8685
transform.rotate(Quat::from_rotation_y(0.08));
8786
}
8887
}

0 commit comments

Comments
 (0)