| Summary: | Emscripten: Use emscripten_sleep() call under SDL_Delay() to allow use Asyncify | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Vitaly Novichkov <admin> |
| Component: | timer | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | Keywords: | target-2.0.14 |
| Version: | HG 2.1 | ||
| Hardware: | Other | ||
| OS: | Other | ||
| Attachments: |
Very simple test of SDL_Delay() working
Adds using of emscripten_sleep() under SDL_Delay() on Emscripten platform to get the full support for asyncify work |
||
|
Description
Vitaly Novichkov
2020-02-18 14:55:33 UTC
Can you provide a tested patch? Thanks! Do you want I'll implement SDL_Delay() for Emscripten myself? Okay, I'll try make that tomorrow after sleep. (My time zone is utc+3). Will reply once I'll have a thing to post here. To test? Easy, I have a project where I can verify that. Great, thanks! One minor question: would it be good as a minor patch into timer/unix/SDL_systimer.c to use `emscripten_sleep()` instead of `nanosleep()` especially on Emscripten, rather building a brand-new module for Esmcripten specific purposes? Okay, I did a very minor test, and it works with one condition: you must specify the "-s ASYNCIFY=1" compile flag to make `emscripten_sleep()` work, otherwise, the browser will throw an exception. Having a next sample: ``` emcc kak.c -o a.html -O2 -L. -lSDL2 -I./include -I../include ``` browser will throw an exception: ``` Please compile your program with async support in order to use asynchronous operations like emscripten_sleep ``` And if compile this sample with using of this command: ``` emcc kak.c -s ASYNCIFY=1 -o a.html -O2 -L. -lSDL2 -I./include -I../include ``` it will work fine. I'll attach the patch and the test program I did use to verify the work of the thing. Created attachment 4233 [details]
Very simple test of SDL_Delay() working
Created attachment 4234 [details]
Adds using of emscripten_sleep() under SDL_Delay() on Emscripten platform to get the full support for asyncify work
The note in the documentation which explains a necessary of -s ASYNCIFY to use these calls: https://emscripten.org/docs/api_reference/emscripten.h.html#pseudo-synchronous-functions Note that this flag is not needed by the library, and avoiding of SDL_Delay() usage will don't require the `-s ASYNCIFY` flag on a client side. Maybe we should have an SDL hint for this? Ryan, after the 2.0.12 release, can you take a look at this? (In reply to Sam Lantinga from comment #9) > Maybe we should have an SDL hint for this? > > Ryan, after the 2.0.12 release, can you take a look at this? I have to read up on this further, but my initial reading of Asyncify is that it's not something you want to rely on. If Emscripten supplies a preprocessor define we can wrap this in (#ifdef ASYNCIFY or whatever), then it's a no-brainer to use it when building SDL in this mode. --ryan. Okay, the Emscripten team recently did something similar in their fork, so I'm pulling it upstream: https://hg.libsdl.org/SDL/rev/e06e70f12286 https://hg.libsdl.org/SDL/rev/dd5a816a4d61 Basically this should Just Work as expected, with and without Asyncify, and there's an SDL hint if for some reason you need to use Asyncify elsewhere and turn it off inside SDL (but by default, if you're using Asyncify, SDL will use emscripten_sleep() as this bug requested). --ryan. |