From 9b599730e818773de98889ebc16979fb2f5d81ba Mon Sep 17 00:00:00 2001 From: Oscar Lorentzon Date: Mon, 21 Sep 2026 12:45:46 -0700 Subject: [PATCH] Wait for WebAssembly setup before writing SPZ Writing SPZ never waited for the WebAssembly module, so a call made before loading finished threw a type error. Writing now waits for the module and returns a promise callers must await. --- examples/splat-painter/index.html | 2 +- src/spz.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/splat-painter/index.html b/examples/splat-painter/index.html index 0e56cf5c..d36bdf05 100644 --- a/examples/splat-painter/index.html +++ b/examples/splat-painter/index.html @@ -487,7 +487,7 @@ // Now export the PackedSplats to SPZ console.log("Writing splats to SPZ..."); - const { fileBytes: spzBytes } = writeSpz(newPackedSplats, ioOptions.maxSh, ioOptions.fractionalBits); + const { fileBytes: spzBytes } = await writeSpz(newPackedSplats, ioOptions.maxSh, ioOptions.fractionalBits); console.log("Creating download..."); const blob = new Blob([spzBytes], { type: "application/octet-stream" }); diff --git a/src/spz.ts b/src/spz.ts index 03d36e22..299beda8 100644 --- a/src/spz.ts +++ b/src/spz.ts @@ -99,16 +99,18 @@ export function writeSpz( splats: PackedSplats | ExtSplats, maxSh?: number, fractionalBits?: number, -): { fileBytes: Uint8Array }; +): Promise<{ fileBytes: Uint8Array }>; export function writeSpz( splats: PackedSplats | ExtSplats, options?: WriteSpzOptions, -): { fileBytes: Uint8Array }; -export function writeSpz( +): Promise<{ fileBytes: Uint8Array }>; +export async function writeSpz( splats: PackedSplats | ExtSplats, maxShOrOptions?: number | WriteSpzOptions, fractionalBits?: number, ) { + await wasm.initialization; + const options: WriteSpzOptions = typeof maxShOrOptions === "number" ? { maxSh: maxShOrOptions, fractionalBits }