Search code examples
c++sdl-2emscripten

Emscripten_set_main_loop not working -- usleep undefined?


My project is compiling and opening up on the web but the main loop is not working. The error seems to be that usleep is undefined. I'm not sure how I can correct this. As per the error message, I seem to be dividing by zero (undefined). I tried removing 'fps' but no luck.

#define emscripten_set_main_loop(func,fps,simulateInfiniteLoop) 
while (1) { func(); usleep(1000000/fps); }

Expands to:

while (1) { loop(); usleep(1000000/0); }
identifier "usleep" is undefined C/C++(20)

Solution

  • Problem solved! I switched over to using emscripten_set_main_loop_arg, put all my variables in a struct, and rewrote my functions to accept pointers to the struct and deal appropriately.