Don't update when suspended to avoid GPU use on iOS. (#2482)
# Objective This fixes a crash caused by iOS preventing GPU access when not focused: #2296 ## Solution This skips `app.update()` in `winit_runner` when `winit` sends the `Suspended` event, until `Resumed`. I've tested that this works for me on my iOS app.
This commit is contained in:
parent
fbf561c2bb
commit
927973ce6a
@ -233,6 +233,8 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
|
|||||||
.get_resource::<WinitConfig>()
|
.get_resource::<WinitConfig>()
|
||||||
.map_or(false, |config| config.return_from_run);
|
.map_or(false, |config| config.return_from_run);
|
||||||
|
|
||||||
|
let mut active = true;
|
||||||
|
|
||||||
let event_handler = move |event: Event<()>,
|
let event_handler = move |event: Event<()>,
|
||||||
event_loop: &EventLoopWindowTarget<()>,
|
event_loop: &EventLoopWindowTarget<()>,
|
||||||
control_flow: &mut ControlFlow| {
|
control_flow: &mut ControlFlow| {
|
||||||
@ -475,14 +477,22 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
|
|||||||
delta: Vec2::new(delta.0 as f32, delta.1 as f32),
|
delta: Vec2::new(delta.0 as f32, delta.1 as f32),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
event::Event::Suspended => {
|
||||||
|
active = false;
|
||||||
|
}
|
||||||
|
event::Event::Resumed => {
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
event::Event::MainEventsCleared => {
|
event::Event::MainEventsCleared => {
|
||||||
handle_create_window_events(
|
handle_create_window_events(
|
||||||
&mut app.world,
|
&mut app.world,
|
||||||
event_loop,
|
event_loop,
|
||||||
&mut create_window_event_reader,
|
&mut create_window_event_reader,
|
||||||
);
|
);
|
||||||
|
if active {
|
||||||
app.update();
|
app.update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user