Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy cannot run in the background on Android #9057

Open
NiklasEi opened this issue Jul 6, 2023 · 9 comments
Open

Bevy cannot run in the background on Android #9057

NiklasEi opened this issue Jul 6, 2023 · 9 comments
Labels
C-Bug An unexpected or incorrect behavior O-Android Specific to the Android mobile operating system P-High This is particularly urgent, and deserves immediate attention

Comments

@NiklasEi
Copy link
Member

NiklasEi commented Jul 6, 2023

Bevy version

main (b61397e) and latest release (0.11.2)

What you did

Run the android example on a real device (Samsung Galaxy S10+). Now press the home button to minimize the app, then open it back up.

What went wrong

The App quits (at least logs do not indicate a crash) and will start from the beginning when reopened.

Additional information

This is a known problem (see some general discussion about life cycle handling in #86), but I couldn't find an open issue for it.

@NiklasEi NiklasEi added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled O-Android Specific to the Android mobile operating system and removed S-Needs-Triage This issue needs to be labelled labels Jul 6, 2023
@griffi-gh
Copy link

griffi-gh commented Aug 25, 2023

Android destroys all active gl/vulkan surfaces when an app is suspended.
To fix this issue Suspended and Resumed winit events need to be handled properly, suspending rendering pipeline (Or fully blocking the evnt loop? which is much easier to implement and makes a lot of sense) on Suspended and replacing the target surface with a new one on Resumed.

@griffi-gh
Copy link

griffi-gh commented Aug 25, 2023

at the moment this is handled by just closing the app whenever it's suspended

event::Event::Suspended => {
runner_state.is_active = false;
#[cfg(target_os = "android")]
{
// Android sending this event invalidates all render surfaces.
// TODO
// Upon resume, check if the new render surfaces are compatible with the
// existing render device. If not (which should basically never happen),
// then try to rebuild the renderer.
*control_flow = ControlFlow::Exit;
}
}

this is not a bug but rather an unimplemented feature.

@alice-i-cecile
Copy link
Member

Summarizing some investigation into this: it appears to require fixes upstream in winit.

Bevy needs to receive and handle both the pause and stop event from Android, but winit does not forward this to us.

Related issues: rust-windowing/winit#2736, rust-windowing/winit#2337

@alice-i-cecile alice-i-cecile added the P-High This is particularly urgent, and deserves immediate attention label Sep 17, 2023
@griffi-gh
Copy link

Summarizing some investigation into this: it appears to require fixes upstream in winit.

Bevy needs to receive and handle both the pause and stop event from Android, but winit does not forward this to us.

Related issues: rust-windowing/winit#2736, rust-windowing/winit#2337

Why is stop evt required to fix this if surface gets destroyed after pause?

@JMS55
Copy link
Contributor

JMS55 commented Jan 20, 2024

@mockersf is this issue complete? If not, what's left?

@alice-i-cecile
Copy link
Member

I believe this is finished: feel free to open new issues for remaining problems.

@mockersf
Copy link
Member

It's not complete at all, we're unable to run in background

@mockersf
Copy link
Member

If not, what's left?

To run in background, we need to be able to run the main app while skipping part of the rendering app.

We can't interact with the GPU in the background, but we need to not miss events to change rendering assets and play them when the app comes back in the foreground

@AbstractiveNord
Copy link

Any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior O-Android Specific to the Android mobile operating system P-High This is particularly urgent, and deserves immediate attention
Projects
None yet
Development

No branches or pull requests

6 participants