emscripten-core / emscripten-core/emscripten

"Cannot set timing mode for main loop" & "You should use 0 for the frame rate in emscripten_set_main_loop"

Open
#7,100 10 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

With the following program…:

```c++
#include
#include

void iterate()
{
}

int main(int, char**)
{
auto pwindow = SDL_CreateWindow
(
"Test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_RESIZABLE
);

auto prenderer = SDL_CreateRenderer
(
pwindow,
-1,
0
);

emscripten_set_main_loop(iterate, 0, 1);

return 0;
}
```

… I get the following error in the web console: `emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up.`

Since `emscripten_set_main_loop_timing` seems to be called by `SDL_CreateRenderer`, I try to fix my program like so:

```c++
#include
#include

void iterate()
{
SDL_Window* pwindow;
SDL_Renderer* prenderer;
static auto first_call = true;

if(first_call)
{
pwindow = SDL_CreateWindow
(
"Test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_RESIZABLE
);

prenderer = SDL_CreateRenderer
(
pwindow,
-1,
0
);

first_call = false;
}
}

int main(int, char**)
{
emscripten_set_main_loop(iterate, 0, 1);

return 0;
}
```

But now I get the following warning in the web console: `Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!`

It seems like there's no way to get neither of those errors.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.