Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when loading opencv.js #7562

Closed
alinpopescu opened this issue Nov 23, 2018 · 10 comments
Closed

Problem when loading opencv.js #7562

alinpopescu opened this issue Nov 23, 2018 · 10 comments
Labels

Comments

@alinpopescu
Copy link

Hello,

I am trying to load opencv.js compiled with these flags:
-s WASM=1 -s USE_PTHREADS=1 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=1610612736 -s PTHREAD_POOL_SIZE=8.

I have added some multithreading module to it which I cannot make public.
First when I simply try to load opencv.js, I get these errors:

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.

I did some investigation and found the problem is in pthread-main.js:101 because e.data.urlOrBlob is undefined. For some reason this line evaluates to undefined:
urlOrBlob: Module["mainScriptUrlOrBlob"] || currentScriptUrl

If I compile the code without -s PTHREAD_POOL_SIZE=8 then the code loads fine, but it blocks when I run it (when the browser tries to load first thread).

Can you please help me fix this problem as I'm facing it for some time and I cannot sort it out?
Why is there a opencv_js.js and opencv.js and how to load them?

Thank you very much for your help,
Alin

@alinpopescu
Copy link
Author

alinpopescu commented Nov 24, 2018

I'm ready to answer any question and even to post some sample code to get this started. @kripken

@yjjnls
Copy link

yjjnls commented Nov 25, 2018

@alinpopescu
Copy link
Author

Thanks much for the answer @yjjnls. I'm doing the loading exactly like that, yet I receive the above error. It must be something wrong with the shared memory between main thread and worker threads.

@AlexVestin
Copy link
Contributor

I had this issue with emsdk and ffmpeg on emsdk 1.XX, the updating stayed on an old version. What version emsdk are you using?

@alinpopescu
Copy link
Author

@AlexVestin Thank you very much for the reply.
I think I have version 1.XX, but I'm not sure. emscripten is 1.38.11. How can I check for sure?

@AlexVestin
Copy link
Contributor

AlexVestin commented Nov 25, 2018

That was poor phrasing, I had 1.37ish ( I can't remember the exact version), but it stayed the same version when I tried to update). So I removed the old version and pulled the repo and now it's 1.38.2 . You can check your version by opening a new terminal and setting the environment variables ie. source [yourpath]/emsdk/emsdk_env.sh.

Also, -s ALLOW_MEMORY_GROWTH=1 throws an error that it is not supported when used with pthreads in this version

@alinpopescu
Copy link
Author

I just updated to 1.38.20 from 1.38.11, removed the -s ALLOW_MEMORY_GROWTH=1 flag and started a build. Will get you updated.

@alinpopescu
Copy link
Author

New day, new error. :) The following happens on 1.38.20 when loading opencv.js multithreading.
LinkError: Import #249 module="env" function="__table_base" error: global import must be a number or WebAssembly.Global object

@stale
Copy link

stale bot commented Nov 25, 2019

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Nov 25, 2019
@stale stale bot closed this as completed Dec 2, 2019
@Zubnix
Copy link

Zubnix commented Jan 7, 2020

For anyone facing the same issue.

Problem:
What's happening is that the main module launches a new worker module and sends this worker module a message telling it where it can find the main module .js file (so the worker can then load the wasm and do it's thing). If you're using a bundler system like webpack then this main module file does not exist as it is bundled together with the rest of your app. As a consequence the worker module receives an 'undefined' url and happily tries to load it.

Minimal action from emscripten:
At the very least emscripten should add an error telling that it can't find a url that points to the main module before sending it to the worker.

Maximum action from emscripten:
Finally provide non-hacked in support for properly exporting and loading ES6/commonjs modules (it is 2020 now after all...).

Possible Workaround:
If your project uses a bundler system, disable emscripten ES6/MODULE flags and use something like webpack's file-loader (with force loader statement like 'import foo from '!file-loader!./MyFoo.js'), this will give you a url where the main module file can be found and allows you to old-school style include the script directly from url. You'll have to do the same for the worker module and set 'locateFile' on the main module so it can find the worker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants