Explorar el Código

[HTML5] Fix Mono builds (old emcc?)

Promise chaining the emscripten module `then` function breaks it badly,
causing an infinite loop.
I'm unsure about the source of the issue, but most likely at this point
is due to the old emscripten version (I remember very old html5 builds
having issue with promise chaining too).

With this commit, we no longer use the module as a promise, and
instantiate it using `Promise` objects directly for compatibility.

(cherry picked from commit ae3c9345cc5d5771bd10165e76048afc77b4015f)
Fabio Alessandrelli hace 4 años
padre
commit
b402c1cb17
Se han modificado 1 ficheros con 16 adiciones y 12 borrados
  1. 16 12
      platform/javascript/js/engine/engine.js

+ 16 - 12
platform/javascript/js/engine/engine.js

@@ -101,19 +101,23 @@ const Engine = (function () {
 				}
 				const me = this;
 				function doInit(promise) {
-					return promise.then(function (response) {
-						return Godot(me.config.getModuleConfig(loadPath, new Response(response.clone().body, { 'headers': [['content-type', 'application/wasm']] })));
-					}).then(function (module) {
-						const paths = me.config.persistentPaths;
-						return module['initFS'](paths).then(function (err) {
-							return Promise.resolve(module);
+					// Care! Promise chaining is bogus with old emscripten versions.
+					// This caused a regression with the Mono build (which uses an older emscripten version).
+					// Make sure to test that when refactoring.
+					return new Promise(function (resolve, reject) {
+						promise.then(function (response) {
+							const cloned = new Response(response.clone().body, { 'headers': [['content-type', 'application/wasm']] });
+							Godot(me.config.getModuleConfig(loadPath, cloned)).then(function (module) {
+								const paths = me.config.persistentPaths;
+								module['initFS'](paths).then(function (err) {
+									me.rtenv = module;
+									if (me.config.unloadAfterInit) {
+										Engine.unload();
+									}
+									resolve();
+								});
+							});
 						});
-					}).then(function (module) {
-						me.rtenv = module;
-						if (me.config.unloadAfterInit) {
-							Engine.unload();
-						}
-						return Promise.resolve();
 					});
 				}
 				preloader.setProgressFunc(this.config.onProgress);