From 1c0abd63931244973fef041ba6eda8b9e924ee29 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 14 Jun 2020 15:14:38 +0200 Subject: [PATCH] Use 2-phase setup in JavaScript. Make the first iteration as soon as the canvas is setup, avoiding a black screen before the next animation frame is requested. Also create OS and do setup before syncing FS to avoid crash when IDBFS access is denied. --- platform/javascript/javascript_main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp index 815bc7e4564..0bafad0af01 100644 --- a/platform/javascript/javascript_main.cpp +++ b/platform/javascript/javascript_main.cpp @@ -42,30 +42,34 @@ extern "C" EMSCRIPTEN_KEEPALIVE void main_after_fs_sync(char *p_idbfs_err) { } OS_JavaScript *os = OS_JavaScript::get_singleton(); os->set_idb_available(idbfs_err.empty()); + Main::setup2(); // Ease up compatibility. ResourceLoader::set_abort_on_missing_resources(false); Main::start(); os->run_async(); + os->main_loop_iterate(); } int main(int argc, char *argv[]) { + new OS_JavaScript(argc, argv); + // TODO: Check error return value. + Main::setup(argv[0], argc - 1, &argv[1], false); + // Sync from persistent state into memory and then // run the 'main_after_fs_sync' function. /* clang-format off */ - EM_ASM( + EM_ASM({ FS.mkdir('/userfs'); FS.mount(IDBFS, {}, '/userfs'); FS.syncfs(true, function(err) { - ccall('main_after_fs_sync', null, ['string'], [err ? err.message : ""]) + requestAnimationFrame(function() { + ccall('main_after_fs_sync', null, ['string'], [err ? err.message : ""]); + }); }); - ); + }); /* clang-format on */ - new OS_JavaScript(argc, argv); - // TODO: Check error return value. - Main::setup(argv[0], argc - 1, &argv[1]); - return 0; // Continued async in main_after_fs_sync() from the syncfs() callback. }