Comments (6)
I was investigating if there is an issue in Winit or if Winit can do something here, just dropping my results here.
So my assumption is that the reason why Event::Suspended
is only received when going back to the tab is because in general all Winit events in Bevy are cached in handled in WindowEvent::RedrawRequested
. But this event has to be handled in the event loop directly and not when WindowEvent::RedrawRequested
is reached (which would be in the next browser event loop tick).
Unfortunately, the spec doesn't specify anymore in which case a browser is allowed or not allowed to freeze a page (and discard it afterwards). To prevent browsers based on Chromium (the only engine currently implementing the Page Lifecycle API) from freezing the page, see this document by Chromium outlining their heuristic.
In the future the spec might officially introduce an opt-out method with the Screen Wake Lock API, see WICG/page-lifecycle#31.
from bevy.
Im not really sure if this should be part of bevy to be honest. The solution mentioned uses the fact that web workers aren't throttled by major browsers (unlike timers in content scripts), however this is (as far as im aware) not standardized and up to the browser for implementation. So it is essentially a temporary fix not a solution as browsers could very well change this behavior at any point. Which leads me to believe that it is not a good idea to rely on this in bevy.
However it might be a good idea to run app.update() whenever the browser fires an visibilitychange
event.
Additionally my solution relies on unsafe casting and will only work in a single threaded environment so it isn't entirely future proof in that aspect either (see multithreading proposal for WebAssembly).
Tldr;
I believe this should be implemented in an independent crate or at least with an optional feature.
from bevy.
Published https://crates.io/crates/bevy_web_keepalive if someone needs a solution until this is fixed upstream (if this gets fixed at all)
from bevy.
tho @happydpc this might not work for you as this only runs the Main schedule, so the renderer subapp wouldn't be affected.
from bevy.
Yeah my issues are fixed with that plugin
from bevy.
In the meantime, for anyone visiting this issue, just use https://crates.io/crates/bevy_web_keepalive
It solves the issue for all browsers by deploying a Web worker which runs the Main
schedule once every (configurable) interval when the window is suspended.
from bevy.
Related Issues (20)
- Bevy should supply types and patterns for interpolating transforms with fixed timesteps HOT 1
- First-party parallax backgrounds
- First-party tile maps HOT 6
- Add Boolean Operations on `Mesh`es HOT 17
- Add non-short-circuiting run conditions and re-rename short-circuiting run conditions to be explicit HOT 9
- Scene spawning doesn't take transform into account anymore HOT 4
- Tracking: `bevy-trait-query` breakage after changes to `WorldQuery` API HOT 15
- Incorrect normals of ConicalFrustum
- Fog toggling shader flag is suboptimal HOT 2
- compute_shader_game_of_life example: `prepare_bind_group` is called every frame HOT 2
- Faint lines between nodes in 0.14.0rc2 HOT 2
- MeshletMesh incorrect depth buffer handling
- MeshletMesh material textures not rendering sometimes HOT 2
- MeshletMesh not writing to the depth prepass
- is_plugin_added is always true for Self
- EventReader:par_read doesnโt mark events as read HOT 1
- I hope to support iOS and Android input methods.
- AssetServer load docs should state that assets don't get loaded multiple times
- Remake PRs targeting 0.14 branch HOT 3
- FocusPolicy does nothing without Interaction HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy.