I have recently started attempting to add WebAssembly into an app I'm working on, but seem to be running into some trouble. I keep getting one of two errors: memory access out of bound or unreachable. I'm attempting to send an Float32Array of length 128 to the wasm module, but its not working. Here is an example of the code I'm using:
zero.ts:
export function zero(arr: number[], length: number): number[] {
for (var i = 0; i < length; i++) {
arr[i] = 0;
}
return arr;
}
and compiling using the following terminal command:
asc zero.ts -o zero.wasm
Then it is used in an AudioWorkletNode like so:
//wasmBytes is passed in form the main thread
var mod;
var importObject = {};
WebAssembly.instantiate(wasmBytes, importObject).then((instance) => {
mod = instance.instance.exports;
var f = new Float32Array(mod.memory.buffer, 0, arr.length);
f.set(arr);
var x = mod.zero(f.byteOffset, arr.length);
});
Any help would be greatly appreciated.