aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-04-08 13:54:23 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-04-08 13:54:23 +0200
commit9d8bb7f4e4f0c541b363a1ee4caccf9e6aa211fa (patch)
treeda5b08e5020021ee3775ed5a9263a0c15aeb743e
parent667883b3d5161e86f92e25619c585292d4bd2526 (diff)
fix `_end` being called before the actual end when using the step function
-rw-r--r--vendor/wasm/js/runtime.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/vendor/wasm/js/runtime.js b/vendor/wasm/js/runtime.js
index 85be84caf..2e69a28c7 100644
--- a/vendor/wasm/js/runtime.js
+++ b/vendor/wasm/js/runtime.js
@@ -1676,6 +1676,9 @@ async function runWasm(wasmPath, consoleElement, extraForeignImports) {
exports._start();
+ // Define a `@export step :: proc(dt: f32) -> (continue: bool) {`
+ // in your app and it will get called every frame.
+ // return `false` to stop the execution of the module.
if (exports.step) {
const odin_ctx = exports.default_context_ptr();
@@ -1687,15 +1690,20 @@ async function runWasm(wasmPath, consoleElement, extraForeignImports) {
const dt = (currTimeStamp - prevTimeStamp)*0.001;
prevTimeStamp = currTimeStamp;
- exports.step(dt, odin_ctx);
+
+ if (!exports.step(dt, odin_ctx)) {
+ exports._end();
+ return;
+ }
+
window.requestAnimationFrame(step);
};
window.requestAnimationFrame(step);
+ } else {
+ exports._end();
}
- exports._end();
-
return;
};