Преглед на файлове

fix `_end` being called before the actual end when using the step function

Laytan Laats преди 1 година
родител
ревизия
9d8bb7f4e4
променени са 1 файла, в които са добавени 11 реда и са изтрити 3 реда
  1. 11 3
      vendor/wasm/js/runtime.js

+ 11 - 3
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;
 };