diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2024-06-14 00:24:30 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2024-06-14 16:04:16 +0200 |
commit | 27d67b5ae6678e264a08d43679677b19301f9710 (patch) | |
tree | 116152e7b98bb3b52b894529a724acca97559541 | |
parent | c95bd2d264c7e8fe49fe04760e51f221d4df42df (diff) | |
download | redot-engine-27d67b5ae6678e264a08d43679677b19301f9710.tar.gz |
[Web] Use the module config to preload GDExtension libraries.
Instead of calling loadDynamicLibraries ourselves, we add the
GDExtension libraries to preload to the "dynamicLibraries" module config
property.
This seems to fix some threading issue with some browsers during the
init phase.
-rw-r--r-- | platform/web/js/engine/config.js | 5 | ||||
-rw-r--r-- | platform/web/js/engine/engine.js | 24 |
2 files changed, 13 insertions, 16 deletions
diff --git a/platform/web/js/engine/config.js b/platform/web/js/engine/config.js index a7134da6fa..8c4e1b1b24 100644 --- a/platform/web/js/engine/config.js +++ b/platform/web/js/engine/config.js @@ -271,12 +271,13 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- */ Config.prototype.getModuleConfig = function (loadPath, response) { let r = response; + const gdext = this.gdextensionLibs; return { 'print': this.onPrint, 'printErr': this.onPrintError, 'thisProgram': this.executable, 'noExitRuntime': false, - 'dynamicLibraries': [`${loadPath}.side.wasm`], + 'dynamicLibraries': [`${loadPath}.side.wasm`].concat(this.gdextensionLibs), 'instantiateWasm': function (imports, onSuccess) { function done(result) { onSuccess(result['instance'], result['module']); @@ -300,6 +301,8 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- return `${loadPath}.audio.worklet.js`; } else if (path.endsWith('.js')) { return `${loadPath}.js`; + } else if (path in gdext) { + return path; } else if (path.endsWith('.side.wasm')) { return `${loadPath}.side.wasm`; } else if (path.endsWith('.wasm')) { diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js index 7e24ad9ae2..04c4c44c5e 100644 --- a/platform/web/js/engine/engine.js +++ b/platform/web/js/engine/engine.js @@ -163,25 +163,19 @@ const Engine = (function () { me.rtenv['initConfig'](config); // Preload GDExtension libraries. - const libs = []; if (me.config.gdextensionLibs.length > 0 && !me.rtenv['loadDynamicLibrary']) { return Promise.reject(new Error('GDExtension libraries are not supported by this engine version. ' + 'Enable "Extensions Support" for your export preset and/or build your custom template with "dlink_enabled=yes".')); } - me.config.gdextensionLibs.forEach(function (lib) { - libs.push(me.rtenv['loadDynamicLibrary'](lib, { 'loadAsync': true })); - }); - return Promise.all(libs).then(function () { - return new Promise(function (resolve, reject) { - preloader.preloadedFiles.forEach(function (file) { - me.rtenv['copyToFS'](file.path, file.buffer); - }); - preloader.preloadedFiles.length = 0; // Clear memory - me.rtenv['callMain'](me.config.args); - initPromise = null; - me.installServiceWorker(); - resolve(); - }); + return new Promise(function (resolve, reject) { + for (const file of preloader.preloadedFiles) { + me.rtenv['copyToFS'](file.path, file.buffer); + } + preloader.preloadedFiles.length = 0; // Clear memory + me.rtenv['callMain'](me.config.args); + initPromise = null; + me.installServiceWorker(); + resolve(); }); }); }, |