mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

ModuleFactory overwrites global "Module" variable thereby interfering with other libraries

Open awmartin opened this issue 6 months ago • 2 comments

Found in code here: https://github.com/google/mediapipe/blob/3a93a5d5d3f90ba3863f14ef4b0a4fc01505d035/mediapipe/web/graph_runner/graph_runner.ts#L929

I'm not sure how the ModuleFactory is defined, but when the build generates the vision_wasm_internal.js file for hand landmark tracking, that code will overwrite the Module variable in the global scope that may be consumed by other libraries. Seen here:

Module overwritten in vision_wasm_interna

One such conflicting library is the WASM version of whisper.cpp, linked below, which also uses a global "Module" variable both in this index file and other included JavaScript files: https://github.com/ggerganov/whisper.cpp/blob/02b4c52c1289e05c8c04ff8370a4835b8ee99c86/examples/whisper.wasm/index-tmpl.html#L247

I'm also not quite sure of the resolution, but global namespace collisions are certainly possible with names as simple as "Module", but I'm also not sure whether this "Module" is a standard and thus needs to be accounted for with any WASM module (particularly when using emscripten), or if this is truly a coincidence. Or is there a way to pass Module variable into the ModuleFactory, say from createFromOptions and the like?

Regardless, it means in this case that whisper.cpp and MediaPipe can't be used together, but again, I'm unclear whether this will be a common collision or just a peculiar one-off.

awmartin avatar Feb 10 '24 18:02 awmartin

Just adding a note that I found that the Module variable is an emscripten construct. Learning as I go. But it still stands that the MediaPipe implementation somehow sets this to "undefined" in the process of starting the vision task. Still looking.

awmartin avatar Feb 10 '24 18:02 awmartin

Hi @schmidt-sebastian,

Could you please have look into this issue? Thank you!!

kuaashish avatar Feb 12 '24 11:02 kuaashish