emscripten-core / emscripten-core/emscripten
Problems in passing data from JS to C++
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I'm trying to fetch the data from a glb.gz over a http request in JS and want to pass it to c++ file.
**index.js:**
const fetchPromise = fetch("https://xxxserver/text_rendering.glb.gz");
fetchPromise.then(response => {
const data = response.arrayBuffer();//This returns an arrayBuffer.
const bufferData = new Uint8Array(data);
})
**main.cpp:**
char * getBufferData() { return buffer; }
main() {....}
EMSCRIPTEN_BINDINGS(my_module) {
function("getBufferData", &getBufferData);
}
index.html:
var Module = {
preRun: [],
postRun: [],
onRuntimeInitialized: function() {
Module.getBufferData(bufferData));
},
Issues im facing:
1. How to pass the bufferdata in JS file to main.cpp file
2. How to make bufferdata in JS to be visible to index.html for usage in onRuntimeInitialized?
3. I tried the https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html in quick_example.js but the module.lerp function doesnt print any logs. onRuntimeInitialized also doesnt print any logs
Kindly support to help me pass the buffer data from browser to cpp file.
Contributor guide
Assessment
This issue has not been assessed yet.