_free function sometimes throws memory access errors
svenoaks opened this issue · 1 comments
svenoaks commented
Depending on what happens before, freeing memory can cause
wasm-001654a2-26:1 Uncaught (in promise) RuntimeError: memory access out of bounds
at wasm-function[26]:0xb03
at Object.Module._free (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:557177)
at start (http://localhost:63343/MusicSpeedChangerWeb/file-saving-worker.js:163:22)
at Object.onReady (http://localhost:63343/MusicSpeedChangerWeb/file-saving-worker.js:7:24)
at Object.Module.onRuntimeInitialized (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:2531)
at doRun (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:563492)
at run (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:563652)
at runCaller (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:563176)
at removeRunDependency (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:19887)
at receiveInstance (http://localhost:63343/MusicSpeedChangerWeb/superpowered-no-module.js:8:508939)
This is from memory allocated with:
let timeStretching = Superpowered.new('TimeStretching', samplerate, 0.25, 1);
let pcm = Superpowered.createFloatArray(blockSizeFrames * 8);
let outputBuffer = Superpowered.createFloatArray(blockSizeFrames * 2);
let pointerL = Superpowered._malloc(blockSizeFrames * 2);
let pointerR = Superpowered._malloc(blockSizeFrames * 2);
let leftInts = new Int16Array(
Superpowered.HEAP16.buffer,
pointerL,
blockSizeFrames
);
let rightInts = new Int16Array(
Superpowered.HEAP16.buffer,
pointerR,
blockSizeFrames
);
let floatL = Superpowered.createFloatArray(blockSizeFrames);
let floatR = Superpowered.createFloatArray(blockSizeFrames);
and then freed after use:
Superpowered.destroyFloatArray(pcm);
Superpowered.destroyFloatArray(outputBuffer);
Superpowered._free(pointerL);
Superpowered._free(pointerR);
Superpowered.destroyFloatArray(floatL);
Superpowered.destroyFloatArray(floatR);
timeStretching.destruct();
When I introduced a library (https://github.com/egoroof/browser-id3-writer) for writing mp3 tags is when the errors starting happening with some files on Superpowered._free(pointerR);.
gaborszanto commented
Maybe that library calls a "grow" on the linear memory, making all pointers invalid.