wasm vfs path fix
Some checks failed
CI / build-test-release (push) Failing after 14m41s

This commit is contained in:
Jorijn van der Graaf 2026-05-19 03:28:27 +02:00
commit b8dc380c33
2 changed files with 49 additions and 34 deletions

View file

@ -301,6 +301,12 @@ if (!wasmUrl) {
// EnableWasiBrowserRuntime) into an in-memory VFS so wasi-libc's file
// syscalls work against them. Browser builds otherwise can't open assets
// shipped alongside the .wasm — sync XHR is too deprecated to rely on.
//
// Manifest entries are relative paths under the bin dir (the layout
// `cfg.assets` produces — e.g. "assets/Inter.ttf",
// "mods/3DForts_Base/foo.cmesh"). We fetch each at its full path but
// key the VFS by basename so `path_open`'s basename-reduction can find
// it regardless of the C++ side's cwd or prefix.
const vfs = new Map();
try {
const manifestResp = await fetch("files.json");
@ -308,8 +314,12 @@ try {
const names = await manifestResp.json();
await Promise.all(names.map(async (name) => {
const r = await fetch(name);
if (r.ok) vfs.set(name, new Uint8Array(await r.arrayBuffer()));
else console.warn(`[wasi] failed to preload ${name}: HTTP ${r.status}`);
if (!r.ok) {
console.warn(`[wasi] failed to preload ${name}: HTTP ${r.status}`);
return;
}
const base = name.split(/[\\/]/).filter(Boolean).pop() || name;
vfs.set(base, new Uint8Array(await r.arrayBuffer()));
}));
}
} catch (e) {