소스 검색

sokol_app.h: clarify sapp_run() behaviour in documentation header

Andre Weissflog 2 년 전
부모
커밋
d10614a5a2
2개의 변경된 파일28개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 0
      CHANGELOG.md
  2. 27 7
      sokol_app.h

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@
   in the GL backend when using an injected texture as framebuffer texture.
   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,
 - 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.
   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
 #### 17-Sep-2023
 
 

+ 27 - 7
sokol_app.h

@@ -951,9 +951,11 @@
 
 
     OPTIONAL: DON'T HIJACK main() (#define SOKOL_NO_ENTRY)
     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
     In its default configuration, sokol_app.h "hijacks" the platform's
     standard main() function. This was done because different platforms
     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
     C's main() (for instance WinMain on Windows has completely different
     arguments). However, this "main hijacking" posed a problem for
     arguments). However, this "main hijacking" posed a problem for
     usage scenarios like integrating sokol_app.h with other languages than
     usage scenarios like integrating sokol_app.h with other languages than
@@ -965,12 +967,30 @@
     - instead provide the standard main() function of the platform
     - instead provide the standard main() function of the platform
     - from the main function, call the function ```sapp_run()``` which
     - from the main function, call the function ```sapp_run()``` which
       takes a pointer to an ```sapp_desc``` structure.
       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
     WINDOWS CONSOLE OUTPUT
     ======================
     ======================