From f1a2985897850321e0a9acb1b74bb41e016deb5c Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 5 Jun 2025 11:42:12 +0200 Subject: Added debug mode to web build and fixed a couple of bugs --- build | 13 ++++++++++--- web/adapter.cpp | 6 ++++-- web/http/nissyapp.mjs | 8 ++++---- web/http/worker.mjs | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build b/build index 8d1e5b9..c920e8a 100755 --- a/build +++ b/build @@ -142,6 +142,7 @@ CPPFLAGS="-std=c++20 -pthread" WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread -mfpu=neon -mrelaxed-simd" WASMCPPFLAGS="-std=c++20 -pthread" +WASMDBGFLAGS="-sASSERTIONS" WASMMFLAGS="-DTHREADS=$THREADS -DNEON" WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE -sEXPORTED_RUNTIME_METHODS=addFunction,UTF8ToString @@ -216,7 +217,7 @@ run() { odflags() { if [ "$debug" = "yes" ]; then echo "$DFLAGS" - else + else echo "$OFLAGS" fi } @@ -283,10 +284,16 @@ build_web() { obj="nissy_web_module" - run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \ + if [ "$debug" = "yes" ]; then + ODFLAGS="$DFLAGS -sASSERTIONS" + else + ODFLAGS="$OFLAGS" + fi + + run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $ODFLAGS -c \ -o nissy.o src/nissy.c || exit 1 run $EMCC -lembind -lidbfs.js \ - $WASMCPPFLAGS $(odflags) $WASMLINKFLAGS -o web/"$obj".mjs \ + $WASMCPPFLAGS $ODFLAGS $WASMLINKFLAGS -o web/"$obj".mjs \ cpp/nissy.cpp web/storage.cpp web/adapter.cpp nissy.o || exit 1 cp web/"$obj".mjs web/http/ cp web/"$obj".wasm web/http/ diff --git a/web/adapter.cpp b/web/adapter.cpp index 3df3a54..9cb2e2d 100644 --- a/web/adapter.cpp +++ b/web/adapter.cpp @@ -151,13 +151,14 @@ int poll_status(void *arg) if (arg == nullptr) return nissy::status::RUN.value; - std::function poll((int (*)(void))arg); + std::function poll((int (*)(void))*(int *)arg); return poll(); } // The parameter js_poll_status is of type int here, but actually it is a // pointer to a JS function. The type will have to be changed to a 64-bit // integer when we move to WASM64. +int js_poll_status_global = 0; nissy::solver::solve_result solve(std::string name, nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, @@ -179,9 +180,10 @@ nissy::solver::solve_result solve(std::string name, // TODO: when running multiple solvers at the same time, we could use // poll_status_id as intended (i.e. an id of some sort) + js_poll_status_global = js_poll_status; return loaded_solvers.at(name).solve(cube, nissflag, minmoves, maxmoves, maxsols, optimal, threads, - poll_status, &js_poll_status); + poll_status, &js_poll_status_global); } EMSCRIPTEN_BINDINGS(Nissy) diff --git a/web/http/nissyapp.mjs b/web/http/nissyapp.mjs index cdfd4d5..b056b5f 100644 --- a/web/http/nissyapp.mjs +++ b/web/http/nissyapp.mjs @@ -267,10 +267,10 @@ function startSolve(solver, scramble) { arg: { solver: solver, scramble: scramble, - minmoves: minSlider.value, - maxmoves: maxSlider.value, - maxsolutions: maxSolsInput.value, - optimal: optimalInput.value, + minmoves: Number(minSlider.value), + maxmoves: Number(maxSlider.value), + maxsolutions: Number(maxSolsInput.value), + optimal: Number(optimalInput.value), threads: window.navigator.hardwareConcurrency, } }); diff --git a/web/http/worker.mjs b/web/http/worker.mjs index 0c1acb9..b988bdd 100644 --- a/web/http/worker.mjs +++ b/web/http/worker.mjs @@ -3,7 +3,8 @@ import Nissy from "./nissy_web_module.mjs" const nissy = await Nissy(); const log = (cstr) => postMessage({ - command: "log", id: -1, + command: "log", + id: -1, object: nissy.UTF8ToString(cstr) }); nissy.setLogger(nissy.addFunction(log, "vp")); -- cgit v1.3