Hello,
After some research and some refactor I did the following:
- In my p3stuff function I call emscripten_set_main_loop(wait_wgets, 0, 0); so the application is not terminated.
- In wait_wgets I call the emscripten_async_wget(imageUrl, path, onLoaded, onError); only the first time the method is called.
- In the onLoaded callback I call emscripten_cancel_main_loop(); and then I call my c code that perform the jpeg stuff.
Problem is:
the p3stuff function has 2 arguments: int p3stuff(char *imgUrl, unsigned char *wrappedkey)
When it's called i have two global variables unsigned char *wrappedKey; and char *imageUrl; which are assigned with the argument like that:
wrappedKey = wrappedkey;
imageUrl = imgUrl;
I do that in order to access the image url from the wait_wgets() or the wrapped key from the onLoaded callback but I think there is some memory management problems cause if I print the url just before calling emscripten_async_wget the imageUrl variable content is completely rubbish but id I don't print anything it works.
So how can I use the global variables in C in order to not get overwritten? Maybe using malloc, or memcopy?
Thanks,
Pau