From 0e657a5f911957767f658f79ec167f831b7cb0dd Mon Sep 17 00:00:00 2001 From: Pablo Escobar Date: Sat, 7 Nov 2020 16:15:18 +0100 Subject: [PATCH] EmscriptenApplication: use existing Module object This prevents deleting elements in Module that were set by Emscripten preamble code when using EmscriptenApplication.js with --pre-js --- src/Magnum/Platform/EmscriptenApplication.js | 98 ++++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.js b/src/Magnum/Platform/EmscriptenApplication.js index 4e77f9b0a..ebd627568 100644 --- a/src/Magnum/Platform/EmscriptenApplication.js +++ b/src/Magnum/Platform/EmscriptenApplication.js @@ -25,55 +25,55 @@ "use strict"; /* it summons the Cthulhu in a proper way, they say */ -var Module = { - preRun: [], - postRun: [], - - arguments: [], - - printErr: function(message) { - console.error(Array.prototype.slice.call(arguments).join(' ')); - }, - - print: function(message) { - console.log(Array.prototype.slice.call(arguments).join(' ')); - }, - - onAbort: function() { - Module.canvas.style.opacity = 0.333; - Module.canvas.style.zIndex = -1; - Module.setStatus("Oops :("); - Module.setStatusDescription("The app crashed. Refresh the page or check the browser console for details."); - }, - - canvas: document.getElementById('canvas'), - status: document.getElementById('status'), - statusDescription: document.getElementById('status-description'), - - setStatus: function(message) { - /* Emscripten calls setStatus("") after a timeout even if the app - aborts. That would erase the crash message, so don't allow that */ - if(Module.status && Module.status.innerHTML != "Oops :(") - Module.status.innerHTML = message; - }, - - setStatusDescription: function(message) { - if(Module.statusDescription) - Module.statusDescription.innerHTML = message; - }, - - totalDependencies: 0, - - monitorRunDependencies: function(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - - if(left) { - Module.setStatus('Downloading...'); - Module.setStatusDescription((this.totalDependencies - left) + ' / ' + this.totalDependencies); - } else { - Module.setStatus('Download complete'); - Module.setStatusDescription(''); - } +var Module = typeof Module !== "undefined" ? Module : {}; + +Module.preRun = []; +Module.postRun = []; + +Module.arguments = []; + +Module.printErr = function(_message) { + console.error(Array.prototype.slice.call(arguments).join(' ')); +}; + +Module.print = function(_message) { + console.log(Array.prototype.slice.call(arguments).join(' ')); +}; + +Module.onAbort = function() { + Module.canvas.style.opacity = 0.333; + Module.canvas.style.zIndex = -1; + Module.setStatus("Oops :("); + Module.setStatusDescription("The app crashed. Refresh the page or check the browser console for details."); +}; + +Module.canvas = document.getElementById('canvas'); +Module.status = document.getElementById('status'); +Module.statusDescription = document.getElementById('status-description'); + +Module.setStatus = function(message) { + /* Emscripten calls setStatus("") after a timeout even if the app + aborts. That would erase the crash message, so don't allow that */ + if(Module.status && Module.status.innerHTML != "Oops :(") + Module.status.innerHTML = message; +}; + +Module.setStatusDescription = function(message) { + if(Module.statusDescription) + Module.statusDescription.innerHTML = message; +}; + +Module.totalDependencies = 0; + +Module.monitorRunDependencies = function(left) { + this.totalDependencies = Math.max(this.totalDependencies, left); + + if(left) { + Module.setStatus('Downloading...'); + Module.setStatusDescription((this.totalDependencies - left) + ' / ' + this.totalDependencies); + } else { + Module.setStatus('Download complete'); + Module.setStatusDescription(''); } };