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
Nasty bug with pauseStarted in a timer #759
Conversation
wait. This also needs to be fixed for code pausing and it seems that manual created timers |
I still have problems with this in my game. The current fix is to use a setTimeout
I am not able to fix this bug at the moment. Maybe you have a better big picture than I. resume: function () {
if (this.running && !this.expired)
{
var pauseDuration = this.game.time.now - this._pauseStarted;
//When I set pauseDuration to 0 before I manual resume the game
//the bug is gone.
//I think this calculation should only be done for a manual pause as the
//timer still runs as opposite to the case that the window was unfocussed
//where we have to catch up to the missed time.
this._pauseTotal += pauseDuration;
for (var i = 0; i < this.events.length; i++)
{
this.events[i].tick += pauseDuration;
}
this.nextTick += pauseDuration;
this.paused = false;
this._codePaused = false;
}
}, |
I've been working through this and have got the various issues resolved across both events and manual Timers, but there is still a clash if you manually pause and then have focus loss. Figuring it out now. |
I'm excited to see how you fix it 👍 |
Alright, I'm quite happy with the version currently in the dev branch. It's got a much more robust pause/resume handler. It took hours to do, but ultimately the solution was really quite simple. Would appreciate if you could give it a quick test. |
And all the problems are gone :) There is only one (somehow related) special scenario still makes problems:
This is the code to to test. Execute it, switch the tab and go back. I know that tab switching is somewhat uncontrollable- so is it worth to dig deeper ? I think the occuring large time delta (when measured) is promising.
Now I will have a look at your changes. Thank you! |
Here another problem: Manual mute > manual pause > manual resume = Sound on Or more explicitly:
|
Ok the latest push fixes the first case with a new timeCap property. I'm only checking it if disableVis is true, but I'm thinking it might be useful to just check all the time anyway - then a system slow down, like Windows grinding would be covered even though the game didn't actually pause or loose vis. |
This is currently an issue when windows lags down too, can confirm. I had
|
Maybe I will enable it all the time then :) |
Now with I can even work around it by delaying the flag setter:
So it's clearly something that happen only during startup. Maybe this should be skipped in the first step ?
|
When are you calling disableVis? For me calling it in the create method appears to be time enough for it to work fine. But if you're doing it earlier than this that may be enough to throw it out. |
I'm doing it in the create method of my state. Also in the create method there is my class creating all those timers. It doesn't matter how I order them, disableVisibilityChange stops them from being executed in the first place. I try to build a demo for this behaviour. |
It's something with manual created timers. The following example won't work unless you set
It's not related to the Regards George |
Ok there - try the new push! Basically Timer._now was never seeded on creation, so the first elapsed went insane. Now handled. Your tests above work fine for me now anyway. |
Ahh lovely error, so the timer is only a little bit delayed :) I can confirm your fix, works for me now 👍 |
Nope I've got a test case for this error already and am part way through fixing it. |
Sound issue fixed :) Here's the test code:
|
YES. Confirmed!
Absolutely. In fact this is the second thing I tested and I would have been disappointed if you had |
Sweet - looking at your P2 / IE9 TypeArray posts now. Figuring I can just use that little shim to sort out my BitmapData changes :) |
That would be great! It would be a shame to let Phaser not fully support IE9 because of some small parts in the code. Maybe you can already merge that p2 change ( Regards George |
…tion of running manual timers (fix #759)
I've added the dataview polyfill into the resources folder in the repo (it's too large to bundle in natively). I've also added the TypedArray shim into Utils and patched it up for jshint. Updated to latest p2.js and included the fixed Float32Array line too. All in all, that should be everything IE9 needs. |
This affects the built in game timer and every other created timer. When you pause the game and you resumes it, it will happen that events - even when you added them after the game already resumed - are delayed by the amount the game LAST was paused. And that can be a lot of seconds. It first seemed to be that the events are lost but they only have a very large delay after a few toggled pause states.
Here a log with the current timer & after the fix. The value of
diff timer/game
in the logshould always be smaller than 500 (the intended delay of the event).
This fix is a one liner. I don't think that it affects other places.
This is the test code. I just rewrote it from coffee script so maybe it's not 100% valid.