openvibers/source.openvibe.games Commits

Force QuickJS switch dispatch on clang-cl (fix JS_Eval crash)

CO Copilot committed 2 Jul 2026 · faa7fe58e6 · 1 file, +14 −0

The flushed client log pinpointed the crash exactly: readFile hook.js ok
-> eval begin -> crash (no eval done). So JS_Eval of the first script
crashes, i.e. the interpreter dispatch. QuickJS defaults to computed-goto
(DIRECT_DISPATCH 1) for non-Emscripten, which miscompiles under clang-cl
and faults in JS_CallInternal on the first eval (Linux/gcc is fine, hence
the native harness worked). Patch the Windows quickjs.c copy to
DIRECT_DISPATCH 0 (switch-based dispatch — the same fallback QuickJS uses
for Emscripten).

Changes

ddiff --git a/tools/build-quickjs-lib-windows.ps1 b/tools/build-quickjs-lib-windows.ps1
iindex 367d482..0444f55 100644
---- a/tools/build-quickjs-lib-windows.ps1
++++ b/tools/build-quickjs-lib-windows.ps1
@@@ -214,6 +214,20 @@ if (Test-Path $QuickJsC) {
} else {
Say 'CONFIG_ATOMICS define not found in quickjs.c copy; pthread shim remains available'
}
++
++ # Force switch-based interpreter dispatch (DIRECT_DISPATCH 0). QuickJS's
++ # computed-goto dispatch (labels-as-values) miscompiles under clang-cl and
++ # crashes JS_CallInternal on the very first JS_Eval — pinpointed via the
++ # flushed client log (readFile ok -> eval begin -> crash on hook.js). This is
++ # the same safe path QuickJS itself uses for Emscripten.
++ $q = Get-Content -Raw $QuickJsC
++ $q3 = $q.Replace("#define DIRECT_DISPATCH 1", "#define DIRECT_DISPATCH 0 /* OpenVibe: clang-cl computed-goto miscompile */")
++ if ($q3 -ne $q) {
++ Set-Content -Encoding ascii $QuickJsC $q3
++ Say 'forced DIRECT_DISPATCH 0 (switch dispatch) for clang-cl'
++ } else {
++ Say 'WARNING: DIRECT_DISPATCH define not found to patch'
++ }
}
Say "compat include=$CompatInclude"