From 8590e0e3fea876637a5f92b388dc382139bb15cb Mon Sep 17 00:00:00 2001 From: Neil Barkhina Date: Sun, 22 Aug 2021 20:08:05 -0400 Subject: [PATCH] Fixed web player bug with filesystem and runtime --- pkg/emscripten/libretro/libretro.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/emscripten/libretro/libretro.js b/pkg/emscripten/libretro/libretro.js index 9d41bfa4c8..607f1e056e 100644 --- a/pkg/emscripten/libretro/libretro.js +++ b/pkg/emscripten/libretro/libretro.js @@ -5,6 +5,7 @@ */ var BrowserFS = BrowserFS; var afs; +var initializationCount = 0; function cleanupStorage() { @@ -42,7 +43,7 @@ function idbfsInit() afs = new BrowserFS.FileSystem.InMemory(); console.log("WEBPLAYER: error: " + e + " falling back to in-memory filesystem"); setupFileSystem("browser"); - preLoadingComplete(); + appInitialized(); } else { @@ -54,7 +55,7 @@ function idbfsInit() afs = new BrowserFS.FileSystem.InMemory(); console.log("WEBPLAYER: error: " + e + " falling back to in-memory filesystem"); setupFileSystem("browser"); - preLoadingComplete(); + appInitialized(); } else { @@ -74,9 +75,20 @@ function idbfsSyncComplete() console.log("WEBPLAYER: idbfs setup successful"); setupFileSystem("browser"); - preLoadingComplete(); + appInitialized(); } +function appInitialized() +{ + /* Need to wait for both the file system and the wasm runtime + to complete before enabling the Run button. */ + initializationCount++; + if (initializationCount == 2) + { + preLoadingComplete(); + } + } + function preLoadingComplete() { /* Make the Preview image clickable to start RetroArch. */ @@ -184,6 +196,10 @@ var Module = arguments: ["-v", "--menu"], preRun: [], postRun: [], + onRuntimeInitialized: function() + { + appInitialized(); + }, print: function(text) { console.log(text);