Emterpret and try to sync async_wget

108 views
Skip to first unread message

Евгений Чудинов

unread,
Jan 24, 2017, 11:13:49 AM1/24/17
to emscripten-discuss
I try to load image from url.
My code looks like (c++):
extern "C" void loadImageSync(const char *url, const char *fileName)
{
    emscripten_wget(url, fileName);
}

This work, but with -s ASYNCFY=1 size of result JS file become ~130mb (It was ~3mb before). This is too heavy for me and I try to use emscripten_async_wget and emscripten_sleep/emscripten_sleep_with_yield like:
loadImage_fileLoaded = false;
emscripten_async_wget(url, fileName, &loadImage_onLoad, &loadImage_onError);
while (!loadImage_fileLoaded) {
    emscripten_sleep(10);
}
And this not work. I try to use -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 and get error about "add functions to whitelist" -- but as far as I understand, this link flags add everything to whitelist.

Error message:
This error happened during an emterpreter-async save or load of the stack. Was there non-emterpreted code on the stack during save (which is unallowed)? You may want to adjust EMTERPRETIFY_BLACKLIST, EMTERPRETIFY_WHITELIST.
Ok, lets add this (that listed in stacktrace) functions to whitelist. But at any added function I get undefined error.
What I need to do? How to load image sync and safe ~small size of file?

Alon Zakai

unread,
Jan 25, 2017, 12:45:55 AM1/25/17
to emscripten-discuss
Looks like we supported emscripten_wget_data in emterpreter mode, but not emscripten_wget (without _data). Should be fixed in

https://github.com/kripken/emscripten/pull/4886

Does that make it work for you?

--
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 emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Евгений Чудинов

unread,
Jan 25, 2017, 6:03:39 AM1/25/17
to emscripten-discuss
I try to run program with this function (just run it), looks that they doing something, but again I got same error (and ~same stacktrace).
Stacktrace:
uncaught exception: abort(-12) at jsStackTrace@http://localhost:8000/Build/Demo-Debug/Demo.js:1176:13
stackTrace@http://localhost:8000/Build/Demo-Debug/Demo.js:1193:22
abort@http://localhost:8000/Build/Demo-Debug/Demo.js:243925:44
_free@http://localhost:8000/Build/Demo-Debug/Demo.js:112914:15
DemoLib/asm._free@http://localhost:8000/Build/Demo-Debug/Demo.js:243611:8
__embind_register_std_string/<.destructorFunction@http://localhost:8000/Build/Demo-Debug/Demo.js:5480:47
Demo$loadJSON@http://localhost:8000/Build/Demo-Debug/Demo.js line 11926 > Function:8:1
@http://localhost:8000/:57:13


This error happened during an emterpreter-async save or load of the stack. Was there non-emterpreted code on the stack during save (which is unallowed)? You may want to adjust EMTERPRETIFY_BLACKLIST, EMTERPRETIFY_WHITELIST.
This is what the stack looked like when we tried to save it: 1,DemoLib/EmterpreterAsync.handle@http://localhost:8000/Build/Demo-Debug/Demo.js:8956:40
_emscripten_wget_data@http://localhost:8000/Build/Demo-Debug/Demo.js:10516:7
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:69760:6
_loadImageSync@http://localhost:8000/Build/Demo-Debug/Demo.js:187039:2
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:62954:6
__ZN17DemoImageLoader9loadImageEP7NString@http://localhost:8000/Build/Demo-Debug/Demo.js:198517:2
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:23477:11
__ZN16DemoJSONParser10parseBrushEP7NObject@http://localhost:8000/Build/Demo-Debug/Demo.js:198527:2
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:23422:11
__ZN16DemoJSONParser9parseJSONEP11NDictionaryP7NObject@http://localhost:8000/Build/Demo-Debug/Demo.js:160452:2
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:62866:6
__ZN6Demo8loadJSONERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE@http://localhost:8000/Build/Demo-Debug/Demo.js:149758:2
emterpret@http://localhost:8000/Build/Demo-Debug/Demo.js:14579:6
__ZN10emscripten8internal13MethodInvokerIM6DemoFvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEEvPS2_JSB_EE6invokeERKSD_SE_PNS0_11BindingTypeIS9_EUt_E@http://localhost:8000/Build/Demo-Debug/Demo.js:124597:2
dynCall_viii@http://localhost:8000/Build/Demo-Debug/Demo.js:236591:2
dynCall_viii_3574@http://localhost:8000/Build/Demo-Debug/Demo.js line 8328 > Function:2:12
Demo$loadJSON@http://localhost:8000/Build/Demo-Debug/Demo.js line 11926 > Function:7:1
@http://localhost:8000/:57:13

May be I use Emterpret wrong?

In Makefile:
DEBUG_OPTS = $(COMMON_OPTS) -O0 -g2 -D__DEBUG__ -Wno-sign-compare -Wno-unknown-pragmas --bind -s ALLOW_MEMORY_GROWTH=1 --profiling-funcs -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
DEBUG_LINKER_OPTS = -s DEMANGLE_SUPPORT=1 -s EXPORT_NAME=\"'DemoLib'\" -s MODULARIZE=1 -s STB_IMAGE=1


Code now looks like:
unsigned char buffer[MAX_BUFFER_MEMORY];
int pnum = 0;
int perror = 0;
emscripten_wget_data(url, (void**)(&buffer), &pnum, &perror);
Log("pnum = %d", "perror = %d", pnum, perror);


Any suggestions?

P.S. I use IMG_Load to decode loaded image, that why I try to use without _data methods.

среда, 25 января 2017 г., 10:45:55 UTC+5 пользователь Alon Zakai написал:

Alon Zakai

unread,
Jan 25, 2017, 2:04:59 PM1/25/17
to emscripten-discuss
Looking at the stack traces, I think that Demo$loadJSON is a method of yours (not from emscripten) that calls into emscripten code? If it does something like this

function Demo$loadJSON(..) {
  ..
  call into compiled code that does an async operation like emscripten_wget
  run any more code (either compiled code, or code that depends on compiled code)
}

Then that won't work. When an async operation happens, we unwind the call stack. That is, we return, which means we go right into "run any more code". If that calls into compiled code (or assumes the compiled code finished running the async operation), it's an error. Instead, you need to wait for the compiled code to resume, which it will asynchronously at some future time.

This limitation is because we can only unwind and resume the call stack for code that we control - which is emterpreted code, and some of our JS wrapper code around it (like emscripten_main_loop support code). But general JS, we can't make it async.


To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Eugene Chudinov

unread,
Jan 25, 2017, 2:20:59 PM1/25/17
to emscripte...@googlegroups.com

Yes, you're right. I started to refactor my code to callback-based architecture...

Thanks for support!


26.01.2017 0:04, Alon Zakai пишет:
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/1ItIu8_SewA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages