3 ms·
I've also noticed that the simulation goes berserk, but only if you leave the page (I mean if you go to an other window or tab). I don't think it's due to Rung
by grondilu 10y ago
I've also noticed that the simulation goes berserk, but only if you leave the page (I mean if you go to an other window or tab). I don't think it's due to Runge-Kutta but rather to the way HTML5/javascript behaves when the page is running in the background.
I have no idea what could be done to avoid it.
- tgb 10y agoThis happened to me, too. My guess is that the simulation stops running when not open, but when it next runs it computes using a time delta calculated by the actual time since the tab was seen. So the integration adds a ridiculous amount of acceleration to the velocity, at which point the whole thing is doomed. This problem: http://gafferongames.com/game-physics/fix-your-timestep/ http://gafferongames.com/game-physics/fix-your-timestep/
- grondilu 10y agoThat looks like a sensible explanation, thanks. I guess I can put a ceiling on dt as a quick work-around.
- throwanem 10y agoI bet you're right! Or close, anyway. From [1]: > The callback rate may be reduced to a lower rate when running in background tabs or in hidden <iframe>s in order to improve performance and battery life. [1] https://developer.mozilla.org/it/docs/Web/API/window/requestAnimationFrame https://developer.mozilla.org/it/docs/Web/API/window/request...
- jchavannes 10y agoYep. This is the code that's causing it[1]: var now = Date.now()/1000; var dt = now - then; Adding this line fixes it: dt = dt > 1 ? 1 : dt; [1] https://github.com/grondilu/grondilu.github.io/blob/47d41d/pendulum-simple.js#L53 https://github.com/grondilu/grondilu.github.io/blob/47d41d/p...