-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
Description
One of the documented features of the Timer class is to avoid large time deltas when the app/page is inactive using the Page Visibility API. This works fine under Chrome, but using Firefox I still observed large delta times. It turns out that requestAnimationFrame callbacks are still being fired by Firefox even when the page is not visible, albeit at an exponentially increasing interval (1s, 2s, 4s, 8s, etc...).
Obviously there's little the Timer can do about requestAnimationFrame still taking place, but it might be worth considering:
- Not letting any time elapse when it has detected that page is hidden (effectively guaranteeing delta = 0 for those "frames")
- Exposing whether or not the Timer is "running" so the user can skip update logic without having to replicate the visibility tracking logic
- Adding a note/warning to the Timer docs about this browser behaviour (not sure if other browsers beside Firefox do this)
One interesting example is webgl_morphtargets_sphere, which worked fine under Firefox, but actually regressed with the merge of #17912 where it switched to the Timer class.
Reproduction steps
- Setup a
Timeras per the docs (https://threejs.org/docs/index.html?q=Timer#examples/en/misc/Timer) - Log the delta time values
- Switch to another tab for several seconds and return
- Notice high delta times being logged (>=1s)
Code
const timer = new Timer();
function animate( timestamp ) {
requestAnimationFrame( animate );
timer.update();
console.log(timer.getDelta()); // Reports >1s deltas under Firefox when page is hidden
renderer.render( scene, camera );
}Live example
The morphtargets_sphere example demonstrates the issue as it has been updated to use Timer instead of Clock + custom page visibility handling:
Screenshots
Version
r160
Device
Desktop
Browser
Firefox
OS
Linux
