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

bug: collision breaks on tab switch #37

Open
neomodulo opened this issue Dec 9, 2024 · 3 comments · May be fixed by #46
Open

bug: collision breaks on tab switch #37

neomodulo opened this issue Dec 9, 2024 · 3 comments · May be fixed by #46

Comments

@neomodulo
Copy link

Describe the bug
This happens in the brand new unmodified 2D starter project. Works fine normally, but when I switch to another tab for a few seconds and come back, the little alien guy has fallen through the floor and the death barrier.

To Reproduce
Steps to reproduce the behavior :

  1. Make a new starter project fibbo init 2d [project-name]
  2. Run it npm run dev
  3. Open the localhost link in your browser and switch to another tab for about 10 seconds.
  4. Alien falls forever.

Expected behavior
Staying on the platform?

Screenshots
Image

Desktop (please complete the following information):

  • Browser: Floorp (Firefox fork)
  • Version: 11.21.0
  • OS: Linux Mint 22
@neomodulo neomodulo added the bug Something isn't working label Dec 9, 2024
@Gugustinette
Copy link
Contributor

Hey !

Yes this is a known bug, switching tab (and sometimes just waiting) can break the collisions.
It must have something to do with Rapier collision system.

This is top priority issue, thanks for opening it ! 👍

@Gugustinette Gugustinette changed the title Collision breaks on unfocused tab bug: collision breaks on tab switch Dec 17, 2024
@Gugustinette Gugustinette moved this to Todo in Fibbo Dec 17, 2024
@Gugustinette Gugustinette moved this from Todo to In Progress in Fibbo Dec 18, 2024
@Gugustinette Gugustinette moved this from In Progress to Todo in Fibbo Dec 18, 2024
@Gugustinette Gugustinette moved this from Todo to In Progress in Fibbo Dec 19, 2024
@Gugustinette
Copy link
Contributor

Gugustinette commented Dec 19, 2024

Pinning some discutions I had with @doppl3r on dimforge Discord

The requestAnimationFrame calls are "paused in most browsers when running in background tabs".

Stepping the physic world by Date.now() - lastFrameTime might make objects go through each other when re-opening a tab that was inactive for too long (as the resulting delta will move the objects "very fast").

Using a Web Worker for running the simulation might help.

Image

@Gugustinette Gugustinette removed the bug Something isn't working label Dec 19, 2024
@Gugustinette Gugustinette linked a pull request Dec 22, 2024 that will close this issue
@Gugustinette
Copy link
Contributor

Gugustinette commented Dec 23, 2024

Decided to not use a web worker, as it is basically impossible to reliably and efficiently sync the scene's data across multiple worker + main thread 30 times per second.

Doing everything in a single web worker is technically achievable however (as in react-three-offscreen) but :

  • It is pretty hard and time consuming to maintain
  • It won't enable direct observability over the scene in the main thread
    • This is required for devtools
    • More generally, it make accessing the scene's data harder (through async calls,...)

For the sake of this issue, I'll keep it simple and make it so the simulation doesn't run when the tab is inactive, and ignore the time that passed.
I'll also try to add a bit more control over the refresh rate (by creating a "pipeline" system) so the simulation can run slower than the rendering or main game loop.

@Gugustinette Gugustinette removed a link to a pull request Dec 23, 2024
@Gugustinette Gugustinette linked a pull request Dec 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants