emscripten-core / emscripten-core/emscripten
opencv_js.worker.js with MODULARIZE generates invalid code
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
hi,
when trying to run opencv.js wasm + simd (works) + threads (there it explodes) with this command:
```js
/home/user/opencv/emsdk/upstream/emscripten/em++ -s WASM=1 -s SINGLE_FILE=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=8 -msimd128 -s ENVIRONMENT=web,worker -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -pthread -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -Wl,--gc-sections --memory-init-file 0 -s TOTAL_MEMORY=128MB -s WASM_MEM_MAX=4GB -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME="'cv'" -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 --use-preload-plugins --bind --post-js /home/user/opencv/emsdk/opencv/modules/js/src/helpers.js -Wno-missing-prototypes @CMakeFiles/opencv_js.dir/objects1.rsp -o ../../bin/opencv_js.js @CMakeFiles/opencv_js.dir/linklibs.rsp
```
the generated worker code contains this part:
```js
Module["wasmMemory"] = e.data.wasmMemory;
Module["buffer"] = Module["wasmMemory"].buffer;
Module["ENVIRONMENT_IS_PTHREAD"] = true;
if (typeof e.data.urlOrBlob == "string") {
importScripts(e.data.urlOrBlob);
} else {
var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
importScripts(objectUrl);
URL.revokeObjectURL(objectUrl);
}
//cv(Module); <-- cv is not defined here
} else if (e.data.cmd === "run") {
Module["__emscripten_thread_init"](e.data.pthread_ptr, 0, 0, 1);
Module["__emscripten_thread_mailbox_await"](e.data.pthread_ptr);
Module["establishStackSpace"]();
Module["PThread"].receiveObjectTransfer(e.data);
```
which has the source here:
https://github.com/emscripten-core/emscripten/blob/58cf85c5b17918c4c3d7ad4f9e0800d68dca2591/src/worker.js#L209
i just commented it out, and it works(?)
* Is this valid to just comment out?
* why is cv not defined, is it a async issue?
* whats the idea of a `cv(Module)` call
Contributor guide
Assessment
This issue has not been assessed yet.