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
Weird behaviour when document is not visible anymore #5
Comments
Hi there, I think the issue is that The best way to check this is by listeing for the I'm not 100% sure this is why your "bug" occures but it would explain it 😄 |
Yes, Mathias is correct. Since You could listen for If you wish to make it record while your document is not visible you could use You can even use const loop = animitter();
//setTimeout requires a millisecond interval
//loop.getFPSLimit() will return Infinity unless you have explicitly set the FPS
//this is because of VR headsets running at 90+
loop.setRequestAnimationFrameObject({
requestAnimationFrame: (fn)=> setTimeout(fn, 1000 / Math.min(60, loop.getFPSLimit()),
cancelAnimationFrame: (id)=> cancelTimeout(id)
}); |
i see and thanks for the link to the specs - this explains all. can you imagine building this feature into animitter, so that it also can deal with visibility changes? this with a new option using the above what do you think guys? |
@MathiasPaumgarten @hapticdata any thoughts on the above? |
This is up to @hapticdata 🤷♂️ But as far as I am concerned, @hapticdata listed a possible solution for you:
I think adding |
yeah, I am mixed on this. Both seem a little outside the scope of animitter({ pauseWhenHidden: true }) but it could also be argued that it would be better to use something like VisibilityJs to avoid another API dependency + polyfill. Using that library you could just do: const loop = animitter().start();
Visiblity.change(()=> loop[ Visibility.hidden() ? 'stop' : 'start']()) still debating |
As far as I understand @binarykitchen's problam, it's not that he wants animitter to pause, but rather to keep runner reliably even if the page is not visible, right? |
@MathiasPaumgarten correct matthias, i want animitter to continue even when not visible anymore. i think this should be in the animitter code as a fallback regardless. because using the above btw, on your readme you say when you already have such a fallback, then why not? ;) |
The fallback occurs for browsers IE9 and older, in this scenario its not wanted as a fallback but to be forced. In general it is not desirable for Its valid to want that behavior for projects that are performing client-side rendering. I have added this type of support in other ways with features like I am opposed to What is the short comings of just using the code I provided in the first comment? |
considering this: exports.useSetTimeout = (options)=>{
var loop = animitter(options);
function raf(fn){
setTimeout(fn, 1000 / Math.min(60, loop.getFPSLimit()));
}
function cancel(id){
cancelTimeout(id)
}
loop.setRequestAnimationFrameObject({
requestAnimationFrame: raf,
cancelAnimationFrame: cancel
});
return loop;
} need some time to think about it and am busy on some other projects for a little while |
worse, what if the user switched between tabs in the browser and comes back to the initial tab? in other words:
getting tricky eh? |
also have experimented here if it's possible to set |
it should work just fine to use What is the issue you are running into when hot-swapping with The main benefit of |
@hapticdata yeah, about the main benefit, i already got that. thanks. i tried that hot-swapping in the middle yesterday, but it didn't work. can you point me to the exact code line where the animitter loop is reading the new request animation frame object? |
certainly, the setRequestAnimationFrameObject is as expected and here is where I deal with a hot-swapped rAF object: https://github.com/hapticdata/animitter/blob/master/index.js#L96-L106 Is it correct that what you are doing is using In WebVR if you try to access pose data from anything but loop
.setRequestAnimationFrameObject(button.manager.defaultDisplay)
.off('update', desktopUpdate)
.on('update', vrUpdate); where in case its useful, heres a gist of one quick WebVR prototype where it works |
exactly, that's the problem! can't do the switch before documents gets hidden. how about adding a new public function to call drawFrame() directly (i know it is ugly but probably the solution for this special case?) - so that it will continue with the new requestAnimationFrameObject (re the VR thing, i dont see how this is relevant here, but good to know) |
VR thing was just to show you that it does respect a new
If you listen for a loop
.stop()
.setRequestAnimationFrameObject(useSetTimeoutObject)
.start() you should be able to keep it going because the first call in onStart is synchronous |
aaah, gotcha! will try that tonight ... |
ah, that worked @hapticdata but now we have the old problem that the frame rate is very wrong when using setTimeout .... oh well :( is there a known trick how to make it work best with setTimeout? |
for now is is the best code i can come with function loopWithTimeouts() {
debug('Recorder: loopWithTimeouts()')
const wantedInterval = 1e3 / options.video.fps // which is 15fps
var processingTime = 0,
start
function raf(fn) {
return setTimeout(
function() {
start = Date.now()
fn()
processingTime = Date.now() - start
},
// reducing wanted interval by respecting the time it takes to
// compute internally since this is not multi-threaded like
// requestAnimationFrame
wantedInterval - processingTime
)
}
function cancel(id) {
clearTimeout(id)
}
setAnimationFrameObject({
requestAnimationFrame: raf,
cancelAnimationFrame: cancel
})
} but it turns out, that when i switch to another browser tab, animitter's deltaTime suddenly jumps from 67ms to 1000ms! this can't be right, when the above timeout is triggered in average about 40ms. a bug? |
It looks like I ran this code on this page in lastest Chrome: last = Date.now();
next = ()=>{
let now = Date.now();
console.log(now-last);
last = now;
setTimeout(next, 40);
};
next(); and got this result, the higher numbers is when I went to another tab:
doesn't look like theres much that can be done about it. If you need the loop = animitter({
fps: 15,
fixedDelta: true
}) |
to pretend? isn't that dangerous? and what disadvantages will fixedDelta come with? |
It isn't dangerous but it also may not serve any utility in your use case. Typically procedural animations such as those you find in games or visualizations will base their animation off of a delta time or a total elapsed time so that animations stay in sync. Say you have made some very nice procedural animation and you decide that you would like to render out the canvas for an image sequence or video; you might not be able to maintain your 60 (or any other) fps framerate while recording. The |
Hello again!
This is probably a question, not sure if it's an animitter bug. The short version is: when the active window aka document looses focus (i.E. I switch to another browser tab), animitter seems to behave funny. Delta- and Elapsed times do not seem right.
The longer version, where it happens:
Thoughts?
The text was updated successfully, but these errors were encountered: