The MODULARIZE option can help with this, it puts everything in a function for you. Each time you call that function you get a completely new instance of everything, that is safe to call.
Another option is to turn the code into a library - without a main() function (that is special and called automatically, and has arguments, etc.), and instead some other functions are exported that you call. Then you can handle global state in them in a way that makes sense. On Fri, Jun 21, 2019 at 10:05 AM Kyo Lee <[email protected]> wrote: > Hi, it's amazing for emscripten build c/c++ program to wasm, and run at a > website ! > > Recently, I try to emcc build ffprobe.bc to ffprobe.wasm, there output two > file : ffprobe.js and ffprobe.wasm > > the ffprobe.js is a bridge to fetch and compile ffprobe.wasm, and run it > by WebAssembly Api at browsers Web Worker > > I use emcc --pre-js --post-js to set my custom change in ffprobe.js > > emcc \ > -s EXIT_RUNTIME=0 \ > -s ENVIRONMENT=worker \ > -s WASM=1 \ > --pre-js pre.js \ > --post-js post.js \ > -o ffprobe.js \ > ffprobe.bc && \ > > My Question Below: > > If I wrapped the compiled code by a function, and work it on Web Worker, > it works good. > > But when run the function multiple, fetch and init ffprobe.wasm will call > multiple. (its slow...) > > I try to find a way to just re run the compiled binary. > > So I change the code,to re run() multiple,below is what I do at my Web > Worker onmessage function : > > self.onmessage = function (e) { > - set noIntialRun: true > - set Module['calledRun'] = false > - set shouldRunNow = true > - call Module['run'](e.data.arguments) > } > > > -------------------------------------------------------------- < > > The result is > > - if i just call arguments = ["-version"], it works well at any times > I call the function > - if i do the FS usage,like arguments = ["-v", "error", > "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", > "csv=s=x:p=0", "/my_data/test_1.flv"],this output the video metainfo width > and height. it works well at first call, and the second time , stderr: > Argument > '/my_data/test2.flv' provided as input filename, but '/my_data/test1.flv' > was already specified. > > The error reason is: > when call run(arguments) at the second time, the arguments have > double length (the old args concat the new args), just like "ffprobe > -version -version" ("-version -version" command can work well. but the FS > usage double length will throw the error -- same behavior at terminal when > ffprobe double -i file) > > is there a way to "RESET arguments" ? > can someone help me ... thx all ! > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/be85ecb3-2b97-419d-b0ea-0f6f3414beae%40googlegroups.com > <https://groups.google.com/d/msgid/emscripten-discuss/be85ecb3-2b97-419d-b0ea-0f6f3414beae%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpSVYtJkk%3D%2BC37nC%3Dgc_j%2BZBf3AGtcqSdWVuLcsvPPBnaA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
