Game does not resume when switching back and forth between tabs
ThaisRobba opened this issue · 9 comments
Describe the bug
Game stops running after changing tabs multiple times.
To Reproduce
Steps to reproduce the behavior:
- Go to Draw Bounds Example
- Change tabs twice
- Come back to the Draw Bounds tab
- Notice the game has stopped
- Change to a different tab
- Come back to the Draw Bounds tab
- Change to a different tab
- Come back to the Draw Bounds tab
- Game will now have resumed
Expected behavior
Game is expected to always resume when its tab is selected.
Desktop (please complete the following information):
- OS: Windows 10
- Browser Firefox
- Version 65.0.2
Desktop (please complete the following information):
- OS: Windows 10
- Browser Chrome
- Version 72.0.3626.121
hi @ThaisRobba
Adding those lines after starting Black should fix your issue.
black.pauseOnBlur = false;
black.pauseOnHide = false;
Understood, thanks :)
There does seem to be a problem with the onVisibilityChange
event (
Line 294 in 75400e3
I'll try to debug it locally.
Ok, did a bit of testing with the base template. The focus event is firing but it is not actually resuming the game because the document.hidden
flag is still set to true. Clicking on the canvas does not fire a second "focus" event and thus, the game is stuck until you switch to a different tab (or select the developer console).
Changing document.hidden
to document.hasFocus()
seems to solve this, but I haven't tested it enough to feel confident that this doesn't break other things.
Hi @ThaisRobba
I'm not able to reproduce this issue. Would you be so kind as to send me some video (maybe)?
Sure thing. Made a tiny video, on a new private window:
I've checked locally and, oddly enough, document.hidden sometimes returns true even though document.hasFocus() is also true. I'm not sure if it is inherent to Firefox, if it is a race condition... but document.hasFocus() seems to work fine.
Although, maybe the document.hidden check could actually be removed, since the engine is already checking for the event type?
Thanks for sharing the video. I can confirm to have same issue randomly.
I just tried this PR: #49
Looks like it fix the issue
I'll try it later today when I'm home :)
That does seem to fix it! There is a regression though (blur no longer works), so either further cleanup would be needed to remove some blur functions or something to add it back.
Fixed in v0.5.10