@@ -46,14 +46,30 @@ extern void emscripten_async_run_script(const char *script, int millis);
46
46
* code assumes that), so you can break the code up into
47
47
* asynchronous callbacks, but you must pause the main
48
48
* loop until they complete.
49
+ *
50
+ * @simulate_infinite_loop If true, this function will throw an
51
+ * exception in order to stop execution of the caller. This
52
+ * will lead to the main loop being entered instead of code
53
+ * after the call to emscripten_set_main_loop being run, which
54
+ * is the closest we can get to simulating an infinite loop
55
+ * (we do something similar in glutMainLoop in GLUT). If this
56
+ * parameter is false, then the behavior is the same as it
57
+ * was before this parameter was added to the API, which is
58
+ * that execution continues normally. Note that in both cases
59
+ * we do not run global destructors, atexit, etc., since we
60
+ * know the main loop will still be running, but if we do
61
+ * not simulate an infinite loop then the stack will be unwinded.
62
+ * That means that if simulate_infinite_loop is false, and
63
+ * you created an object on the stack, it will be cleaned up
64
+ * before the main loop will be called the first time.
49
65
*/
50
66
#if EMSCRIPTEN
51
- extern void emscripten_set_main_loop (void (* func )(), int fps );
67
+ extern void emscripten_set_main_loop (void (* func )(), int fps , int simulate_infinite_loop );
52
68
extern void emscripten_pause_main_loop ();
53
69
extern void emscripten_resume_main_loop ();
54
70
extern void emscripten_cancel_main_loop ();
55
71
#else
56
- #define emscripten_set_main_loop (func , fps ) \
72
+ #define emscripten_set_main_loop (func , fps , simulateInfiniteLoop ) \
57
73
while (1) func();
58
74
#endif
59
75
0 commit comments