raysan5/raylib

[rcore] uncapped framerate not working properly with SDL platform

mpalomas opened this issue · 3 comments

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

(this is on latest master commit)

When compiling with the SDL platform, removing/not using SetTargetFPS does not seem to really work: framerate is actually matching the screen refresh rate.

  • Take any example, just remove SetTargetFPS(60)
  • Then right after BeginDrawing(), add DrawFPS(10, 10);

When doing this with the GLFW platform, you basically get unlocked/uncapped framerate: in my case it can be more than 10000-20000 FPS depending on the example.

When doing this exact same thing, but with SDL platform, I get 115-120 FPS, which is really close to my screen refresh rate (120 HZ).

Environment

  • Ubuntu 23.10 x86_64 under Gnome
  • AMD Ryzen 9 7900 + AMD Radeon 5700XT
  • SDL Platform

Issue Screenshot

With GLFW platform
image

With SDL platform
image
image

Code Example

  • Just take for instance textures_image_loading.c
  • Comment out SetTargetFPS
  • Add DrawFPS
  • Build first with GLFW, then with SDL
  • Observe completely different framerate

@mpalomas This is strange, could it be that SDL enables VSync by default?

Strange indeed. No expert but I know that when using OpenGL, SDL controls vsync with https://wiki.libsdl.org/SDL2/SDL_GL_SetSwapInterval
As you can see, 0 means immediate, 1 is vsync. Need to look at the platform implementation, will try spend time this evening.