diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-13 10:06:33 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-13 10:06:33 -0700 |
commit | 45ba35aa01f1650ed28479976262236bbf204ef1 (patch) | |
tree | a45ef1240a00776b9fd0b0b9b1a89b877848b474 /tests/emscripten_api_browser_infloop.cpp | |
parent | 3a156a34e83fa301b8abbac6effdb5bd21d9be11 (diff) |
add parameter to emscripten_set_main_loop to optionally simulate an infinite loop by throwing an exception (like glutMainLoop)
Diffstat (limited to 'tests/emscripten_api_browser_infloop.cpp')
-rw-r--r-- | tests/emscripten_api_browser_infloop.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/emscripten_api_browser_infloop.cpp b/tests/emscripten_api_browser_infloop.cpp new file mode 100644 index 00000000..0fd41922 --- /dev/null +++ b/tests/emscripten_api_browser_infloop.cpp @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <string.h> +#include <emscripten.h> + +struct Class { + static Class *instance; + + int x; + + Class() : x(0) {} + + void print() { + char buf[18]; + memset(buf, 0, 18); // clear stack. if we did not simulate infinite loop, this clears x and is a bug! + x += buf[7]; + + printf("waka %d\n", x++); + + if (x == 7) { + int result = x; + REPORT_RESULT(); + } + } + + static void callback() { + instance->print(); + } + + void start() { + instance = this; + emscripten_set_main_loop(Class::callback, 3, 1); // important if we simulate an infinite loop here or not + } +}; + +Class *Class::instance = NULL; + +int main() { + Class().start(); + return 1; +} + |