[Bug] On an Apple device, if you switch the game to the background and then switch it back, the game will stop rendering and cannot run again
On Apple devices, including (webview, chrome, Safari), if you switch the game to the background and then switch it back, the game will stop rendering and cannot run again
Demo: Choose any game and you can reproduce it https://demo.emulatorjs.org/
Is there any way to solve this problem?
This has been reported before, in the discord server. Going to give the same answer I gave there
Pause the game if you are switching windows. If you want the bug to be fixed, I expect your contribution since I do not own an iPhone, and therefore cannot even attempt to reproduce the issue
including (webview, chrome, Safari)
There is no difference between using chrome and safari (and any other browser) on iOS, since they are all just WebKit wrappers. Its just whether or not you want to give google your data or not
I also encountered the same problem
@wu928320442 a PR is welcome if you can debug and fix the issue
@wu928320442如果你能调试并修复这个问题,欢迎提交 PR
@ethanaobrien I added a visibilitychange listener in the bindListeners method of EmulatorJS. This can address the issue of play and pause when switching tabs on PC web pages, and it can also be listened to on mobile. It works normally on Android.However, there is a problem in ios.Sometimes it can resume running, and sometimes it can't. When it can't resume, repeating the switch between foreground and background a few times makes it work again. You can check if there are any other issues.The code is as follows:
this.addEventListener(window, "visibilitychange", (e) => {
if (document.hidden) {
setTimeout(() => {
this.pause(true);
}, 0);
} else {
setTimeout(() => {
this.play(true);
}, 0);
}
});
@wu928320442 the method you've used seems to be somewhat of a workaround rather than a bug fix (you mentioned the issue is still present on iOS). For a bug fix to be pushed to the code, it should be working 100% of the time
@wu928320442 the method you've used seems to be somewhat of a workaround rather than a bug fix (you mentioned the issue is still present on iOS). For a bug fix to be pushed to the code, it should be working 100% of the time
@ethanaobrien Currently, the logic seems to be normal, including adding visibility calls for pause and play events, which are correct, and the corresponding C++ wrapper methods are also called. However, on iOS, even without adding a pause for invisibility, it will pause by itself because iOS has some restrictions in the background. I was thinking if we could wrap some recovery methods in EJS_GameManager, such as redrawing the Canvas or sound when resuming the game. It would be better if we could make the play method in toggleMainLoop compatible; if not, it would be helpful to provide some methods.
Moreover, when iOS is showing a freeze, using the Reset button in the menu is also ineffective, even though the API has been called.
That's not how that works, everything you mentioned is handled by the RetroArch back end and cant "just" be reset