-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
Context: https://x.com/noname20310/status/1862416380278317407
I've check the potential WASM memory view invalidation bug.
The conclusion is that there are no bugs in the code.
https://github.com/drumath2237/spz-loader/blob/main/packages/core/lib/spz-wasm/cppBufferUtil.ts#L18
The reason is that as soon as the ArrayBufferView is created, the contents are copied to the ArrayBuffer on the js side and the View is no longer used.
export const floatVectorToFloatArray = (
wasmModule: MainModule,
vec: VectorFloat32,
enhancementFunc: (n: number) => number = (n) => n,
): Float32Array => {
const pointer = wasmModule.vf32_ptr(vec);
const size = vec.size();
// buffer is ArrayBufferView of WASM Memory
const buffer = new Float32Array(wasmModule.HEAPF32.buffer, pointer, size);
// copiedBuffer is referencing js side new ArrayBuffer instance
const copiedBuffer = buffer.map(enhancementFunc);
return copiedBuffer;
};The problem starts when you save the ArrayBufferView as a member of the class as is or as a member of an object, and you need to check for invalidation, but I don't see any such cases in the code.
I apologize for the confusion. You can close this issue once you've read it.
drumath2237drumath2237
Metadata
Metadata
Assignees
Labels
Projects
Status
👀 In review