-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emscripten main loop hack #843
Comments
Don't know tbh, I just tried the reverse by putting your code into sokol_app.h and that worked (even though it passes zero to the time parameter of the _sapp_emsc_frame() function (which I would expect to cause problems, e.g. divisions by zero). Is your PS: compiling and linking also works without problems? At first I had linker problems when adding |
Hi. Thanks for your reply. Standard Sokol emsc flow, i get one frame called and that's it. Here's what happens;
then;
This renders a single frame, and then returns from Then everything stops! However Doing this;
Does not return! and does not return to So; Is it something i'm doing that means returning to Also, FYI, I do have (and use) a filesystem which means i've removed the |
Does your _SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) {
// ....
return EM_TRUE;
} Looking at git-blame, the old frame function which used For instance see here: if Lines 5804 to 5810 in 177e2c7
(...so the other thing to check would be if |
Thanks for the suggestion. I tried that, but it wasn't the problem. I commented the whole thing out in Then; I had a go at building the sokol-sample
I thought perhaps stuff like The So then i went in and changed the code of Also works fine! As you see from the script above, I'm pointing it to the same imgui and sokol I'm using for my app (any hacks included). This is really weird; build my app and blank screen, build Put my hack, Now I'm stumped. |
@voidware any new info on this? Can the ticket be closed? |
Hi, I'm glad to find an existing discussion on the topic, cos I'm also struggling to make sense of what I'm experimenting. I'll share my findings. Using saap with SOKOL_NO_ENTRY, I noticed that saap_run returns (ie is not blocking) even before init cb is called. I think it works with sokol examples, because of the -NO_EXIT_RUNTIME=1 linker option, which means the program will continue to execute even after main (and saap_run) has exited.
I couldn't make NO_EXIT_RUNTIME work, but that's another discussion. I'll test emscripten_set_main_loop, thanks for the tips. Hope it helps, |
Hmm, looking at https://github.com/emscripten-core/emscripten/blob/c65a321b603de497aa0168f542a88e95e88264a4/src/settings.js#L83-L93, I can confirm that the sokol samples have trouble when the exit runtime is enabled though (most likely because the samples keep state in global variables and this might be zeroed out when main() returns and the exit runtime runs. The behaviour that the main() function returns immediately is entirely normal on Emscripten, otherwise the browser event loop would appear to be stuck and the tab would be killed after a few seconds (unless tricks like ASYNCIFY are used), and from that perspective it's also correct that the exit runtime is disabled by default, because global state must stay alive after main() returns. Also any actions on exit don't make a lot of sense anyway when running in the browser, because the user can close the tab at any time, and this will just stop the application without it having a chance to run any "exit code" (there's a |
Hi, Removing NO_EXIT_RUNTIME (as it's the default behavior) is a good idea indeed. I'm starting understanding my main blocker: -sASSERTIONS=1 seems to force EXIT_RUNTIME (at least throw assertions when crt functions are called after exit). For now I need to force -sASSERTIONS=0 even in debug.
This is not what I was expecting after reading this comment about sapp_run : https://github.com/floooh/sokol/blob/master/sokol_app.h#L970
The code executed after sapp_run is actually destructors from objects on the stack, which works ok on other platforms. Cheers, |
Ooops, yeah that comment is most likely a leftover from when sokol_app.h was using
Be aware though that on iOS, it also isn't guaranteed that exit code is called. There are situations where the OS will simply terminate the application (even without calling the iOS specific |
@guillaumeblanc I have clarified sapp_run() behaviour in that outdated comment section: Lines 952 to 993 in d10614a
...I also wonder if it would make sense to add a config-boolean to |
Hi, Fixing the documentation was the most important part. It's pretty clear now. Why do you say that "An application also should not depend on the cleanup-callback being called" ? Using emscripten_set_main_loop would make emscripten behavior closer to other platforms, with 2 code paths instead of 3. Thanks a lot !! |
There's (at least) two platforms where this can happen:
In general, you should put your cleanup code into the sokol_app.h cleanup callback, because that is the most portable solution. sokol_app.h just cannot guarantee that the cleanup function will be called on all platforms (generally in cases where the 'system' simply terminates the application, without giving the application an opportunity to react). As for why (note that |
All clear. I agree that cleanup cb is the most portable solution, I switched to it. If you ask me, I'd switch to emscripten_set_main_loop without adding a new option. It would make sapp_run behavior closer to other platforms, the documentation simpler and the api less error-prone. You can get timestamp with Hope it helps. |
My hope with getting the timestamp from the requestAnimationFrame() callback is that it contains less jitter then calling performance.now() at the start of my own callback. Ideally, the rAF timestamp would be the time of when the last frame was presented, similar to native swapchain APIs, but that may be a little much to hope for. Also, there this an interesting property of the timestamp that even though it has limited precision on some browsers (e.g. on Safari it's only 1ms granularity), taking the average over a couple of frames gives an exact result (e.g. 16.667ms on 60Hz displays or 8.333ms on 120Hz displays), I don't know if this is an intended feature of the RAF timestamp, or just the regular sideeffect of filtering a noisy random signal though (but since Safari only returns full milliseconds, e.g. 16.0 or 17.0, but simply rounding a jittery signal would always tend towards 17.0, I'm thinking it's intentional. |
My experience on this topic: I am using the I can not make the current main loop setup (using To add to the discussion about the timestamp. From: On the other end MDN states hand wavily:
I wonder if the jitter is something that could be measured. |
My current preferred solution would be to add a new config bool to Here's a different PR for reference (which is missing the selection between rAF and set_main_loop though): |
option on Yes please. That would be splendid. Thanks. |
What about something like this? Edit: Oops, I just realized you were talking about a runtime bool and not compiled time option as in #997. I wonder if the ability to choose at runtime option is useful though. Specially since some of the other compile time options can make the whole app freeze if not using |
@Dvad I would really prefer a runtime bool because it keeps the number of builds down (e.g. I can add a sample which uses set-main-loop method without having to mess around in the build system and/or build a separate sokol library). |
Ok, PR #997 has been merged. I also added a separate config option for the |
Thanks for this. I can report everything is working here spiffingly. Also the other breaking changes i needed to fix. Thanks for the excellent docs on migration. All good. |
Hi,
Just got the latest code. A few minor changes needed here, no problems. Seems working fine. thanks.
So;
I'd really like to eliminate my Sokol hacks in
sokol_app.h
so to use the official codebase. Firstly, thanks for fixing theemsc_event->code[0]
keyboard problem. One less hack of mine needed!This is an emscripten build and I thought I'd try to eliminate another hack. I've had this hack in my code for over a year and it works fine, but the official code just produces a blank screen with no errors.
and;
I'm at a loss to explain why the official main loop doesn't work and mine does because i can't see anything wrong with it.
Any ideas? Thanks.
The text was updated successfully, but these errors were encountered: