Skip to content

Commit

Permalink
sokol_app.h: clarify sapp_run() behaviour in documentation header
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Sep 18, 2023
1 parent 1d767d2 commit d10614a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
in the GL backend when using an injected texture as framebuffer texture.
- Issue https://github.com/floooh/sokol/issues/884 has been fixed via PR https://github.com/floooh/sokol/pull/894,
this adds missing error code paths in the Metal backend when Metal object creation fails.
- Clarified `sapp_run()` behaviour in the sokol_app.h documentation header (search for `OPTIONAL: DON'T HIJACK main()`)

#### 17-Sep-2023

Expand Down
34 changes: 27 additions & 7 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,11 @@
OPTIONAL: DON'T HIJACK main() (#define SOKOL_NO_ENTRY)
======================================================
NOTE: SOKOL_NO_ENTRY and sapp_run() is currently not supported on Android.
In its default configuration, sokol_app.h "hijacks" the platform's
standard main() function. This was done because different platforms
have different main functions which are not compatible with
have different entry point conventions which are not compatible with
C's main() (for instance WinMain on Windows has completely different
arguments). However, this "main hijacking" posed a problem for
usage scenarios like integrating sokol_app.h with other languages than
Expand All @@ -965,12 +967,30 @@
- instead provide the standard main() function of the platform
- from the main function, call the function ```sapp_run()``` which
takes a pointer to an ```sapp_desc``` structure.
- ```sapp_run()``` takes over control and calls the provided init-, frame-,
shutdown- and event-callbacks just like in the default model, it
will only return when the application quits (or not at all on some
platforms, like emscripten)
NOTE: SOKOL_NO_ENTRY is currently not supported on Android.
- from here on```sapp_run()``` takes over control and calls the provided
init-, frame-, event- and cleanup-callbacks just like in the default model.
sapp_run() behaves differently across platforms:
- on some platforms, sapp_run() will return when the application quits
- on other platforms, sapp_run() will never return, even when the
application quits (the operating system is free to simply terminate
the application at any time)
- on Emscripten specifically, sapp_run() will return immediately while
the frame callback keeps being called
This different behaviour of sapp_run() essentially means that there shouldn't
be any code *after* sapp_run(), because that may either never be called, or in
case of Emscripten will be called at an unexpected time (at application start).
An application also should not depend on the cleanup-callback being called
when cross-platform compatibility is required.
Since sapp_run() returns immediately on Emscripten you shouldn't activate
the 'EXIT_RUNTIME' linker option (this is disabled by default when compiling
for the browser target), since this would be called immediately at
application start, causing any global objects to be destroyed and global
variables to be zeroed.
WINDOWS CONSOLE OUTPUT
======================
Expand Down

0 comments on commit d10614a

Please sign in to comment.