SDL_AppIterate called too many times

I am using SDL3 directly from github. I am trying the main functions.

The problem is that SDL_AppIterate is being called 100000 per second.

Inside SDL_AppInit, I am calling

  SDL_SetHint(SDL_HINT_MAIN_CALLBACK_RATE, "60");

But with or without it, the result does not change.

It is a Debian GNU/Linux with Gnome and Wayland. The environment variable SDL_VIDEO_DRIVER=wayland is set. The window is, in fact, a wayland window. The window was created and is rendered in another thread.

The rate is only limited when there is no window.

SDL_sysmain_callbacks.c contains the following comment:

// !!! FIXME: maybe respect this hint even if there _is_ a window.
// if there's no window, try to run at about 60fps (or whatever rate
//  the hint requested). This makes this not eat all the CPU in
//  simple things like loopwave. If there's a window, we run as fast
//  as possible, which means we'll clamp to vsync in common cases,
//  and won't be restrained to vsync if the app is doing a benchmark
//  or doesn't want to be, based on how they've set up that window.
if ((callback_rate_increment == 0) || SDL_HasWindows()) {
    next_iteration = 0; // just clear the timer and run at the pace the video subsystem allows.

It seems there is a decision to be made.

The documentation says:

This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates.

Complex default

Instead of 60, the default could be:

  1. 60 if there is no window.
  2. No wait (next_iteration = 0) when there is a window.

However, if someone does set the hint (to 60 or not), it should probably be followed. Since we do not have proper means do determine “if the app is doing a benchmark” or “the app doesn’t want […]”… this is exactly what hints are for, I suppose.

Simpler default

The “no wait behaviour” could be set when the hint is 0 (or infinity), for example. As I think it is already the case when we have no windows.

It is much better if the default is:

  1. What the system dictates as good.
  2. 60 if the system does not dictate anything.

If the person really wants “no wait”, this can be informed through the hint. No heuristics from SDL on what the app probably wants.

I guess this probably just means following the first line of the FIXME note:

respect this hint even if there is a window.

I suppose this would be achieved by simply removing the || SDL_HasWindows() from the if-statement. The behaviour rate = 0 means infinity is already there.