Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
[Web] better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nokotan committed Apr 24, 2024
1 parent d91d152 commit d9c4e4b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
16 changes: 2 additions & 14 deletions Siv3D/lib/Web/jslib/Siv3D.System.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ mergeInto(LibraryManager.library, {
let awake = siv3dAwakeFunction;
siv3dAwakeFunction = null;

try {
awake();
} catch (e) {
handleException(e);
} finally {
maybeExit();
}
callUserCallback(awake);
}
},
siv3dMaybeAwake__sig: "v",
Expand All @@ -187,13 +181,7 @@ mergeInto(LibraryManager.library, {
siv3dRequestAnimationFrame: function() {
Asyncify.handleSleep(function(wakeUp) {
requestAnimationFrame(function() {
try {
wakeUp();
} catch (e) {
handleException(e);
} finally {
maybeExit();
}
callUserCallback(wakeUp);
});
});
},
Expand Down
27 changes: 13 additions & 14 deletions Siv3D/lib/Web/jslib/Siv3D.pre.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
(function()
{
Module["onAlert"] = Module["onAlert"] || function(text) {
window.alert(text);
};

const originalOnAbort = Module["onAbort"];
const onAbort = Module["onAbort"] || ((e) => {
window.alert(e);
});

Module["onAbort"] = function(e)
{
Expand All @@ -17,27 +15,28 @@ Please refer https://webassembly.org/roadmap/ to check which webassembly feature
\
Original Error: " + e;

Module["onAlert"](additionalMessage);
onAbort(additionalMessage);
}
else if (e instanceof ProgressEvent)
{
Module["onAlert"]("Browser seems to blocked fetch required assets. \
onAbort("Browser seems to blocked fetch required assets. \
The application has been launched from explorer, which is not supported. \
Please launch emrun or your favorite HTTP server and access this application through it.");
}
else if (e instanceof ReferenceError && e.message.includes("WebAssembly"))
{
Module["onAlert"]("The application cannot be launched with this browser. \
onAbort("The application cannot be launched with this browser. \
The application requires that this browser supports WebAssembly, which seems to be not available in this browser.\
Please use another browser that supports WebAssembly.")
}
else if (typeof e === "string" && e !== "" && e !== "native code called abort()")
else
{
Module["siv3dSetThrowJSException"](e);
}

if (originalOnAbort) {
originalOnAbort(e);
onAbort(e);
}
// Test stub: throw JSException instead of abort.
// else if (typeof e === "string" && e !== "" && e !== "native code called abort()")
// {
// Module["siv3dSetThrowJSException"](e);
// }
};
})();
13 changes: 6 additions & 7 deletions Web/App/Templates/Embeddable/web-player.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@

let hasRaiseRuntimeError = false;

function onRuntimeError() {
function handleRuntimeError(e) {
document.querySelector(".error-text").textContent = e.toString()

progressElement.classList.add('progress-error');
progressElement.style.width = '100%';
progressElement.hidden = false;
Expand All @@ -378,10 +380,8 @@
preRun: [],
postRun: [ doResize, onAudioInit ],
onAbort: function (e) {
onRuntimeError();
},
onAlert: function (text) {
document.querySelector(".error-text").textContent = text;
handleRuntimeError(e);
Options.onRuntimeExit();
},
canvas: (function () {
var canvas = document.getElementById("canvas");
Expand All @@ -392,8 +392,7 @@
canvas.addEventListener(
"webglcontextlost",
function (e) {
alert("WebGL context lost. You will need to reload the page.");
onRuntimeError();
handleRuntimeError("WebGL context lost. You will need to reload the page.");
e.preventDefault();
},
false
Expand Down

0 comments on commit d9c4e4b

Please sign in to comment.