Use Module.HEAP8.set Get messed data

Viewed 2639

I use emscripten compile the c code into asm.js my c code like this:

 int _call_main(char* p, int number)//p is the start arrary, number is the lengh

I want to send a bytearray data to the c code, My Js code like this:

var decode_encode_audio = Module.cwrap('_call_main', 'number', ['array','number']);
........
var byteArray = new Uint8Array(message.data);//audio data
var offset = Module._malloc(70000);
Module.HEAP8.set(byteArray, offset);
decode_encode_audio(offset , byteArray.length);

In the C code, I print the point p array, I got a messed data, the start part and the end part of p is correct(I save the file), However, In the middle part is messed.I replace the function(Module.HEAP8.set) with [Module.HEAPU8.set],also got error. I don't know why?

I change the Js code :

var decode_encode_audio = Module.cwrap('_call_main', 'number', ['number','number']);//not array
........
var byteArray = new Uint8Array(message.data);//audio data
//var offset = Module._malloc(70000);
//Module.HEAP8.set(byteArray, offset);
decode_encode_audio(byteArray, byteArray.length); 

I can get correct data.

Can anyone tell me what's wrong with "Module.HEAP8.set" method.

1 Answers
Related