Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

web: Expose emscripten_force_exit to JS

Fabio Alessandrellid4cf591e4e88
diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js
index 0261ca55b7a..59be0d0c418 100644
--- a/platform/web/js/engine/engine.js
+++ b/platform/web/js/engine/engine.js
@@ -235,6 +235,19 @@ const Engine = (function () {
}
},
+ /**
+ * Forcibly exit the current instance.
+ *
+ * This is akin terminating the process on a regular OS, and *may* be able to terminate
+ * the engine and free resources even if the engine has crashed, or is stuck in a loop.
+ *
+ */
+ forceQuit: function () {
+ if (this.rtenv) {
+ this.rtenv['force_quit']();
+ }
+ },
+
/**
* Editor-Only.
*
@@ -272,6 +285,7 @@ const Engine = (function () {
Engine.prototype['startGame'] = Engine.prototype.startGame;
Engine.prototype['copyToFS'] = Engine.prototype.copyToFS;
Engine.prototype['requestQuit'] = Engine.prototype.requestQuit;
+ Engine.prototype['forceQuit'] = Engine.prototype.forceQuit;
Engine.prototype['addDebuggerSession'] = Engine.prototype.addDebuggerSession;
Engine.prototype['installServiceWorker'] = Engine.prototype.installServiceWorker;
// Also expose static methods as instance methods
diff --git a/platform/web/js/libs/library_godot_os.js b/platform/web/js/libs/library_godot_os.js
index 6773306bc1f..3e7d0ab2678 100644
--- a/platform/web/js/libs/library_godot_os.js
+++ b/platform/web/js/libs/library_godot_os.js
@@ -242,6 +242,7 @@ const GodotOS = {
$GodotOS__deps: ['$GodotRuntime', '$GodotConfig', '$GodotFS'],
$GodotOS__postset: [
'Module["request_quit"] = function() { GodotOS.request_quit() };',
+ 'Module["force_quit"] = function(code) { _emscripten_force_exit(code ?? 1) };',
'Module["onExit"] = GodotOS.cleanup;',
'GodotOS._fs_sync_promise = Promise.resolve();',
].join(''),