Skip to content

Commit

Permalink
display_set_fps_limit: sanitize input argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Dec 9, 2024
1 parent a7f77a7 commit 4f21412
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,18 @@ float display_get_delta_time(void)

void display_set_fps_limit(float fps)
{
assert(fps >= 0.0f);

disable_interrupts();

min_refresh_period = 1.0f / (fps ? fps : refresh_rate);
min_refresh_period = 1.0f / (fps ? MIN(fps, refresh_rate) : refresh_rate);
frame_skip = refresh_period / min_refresh_period;
delta_time = min_refresh_period;

// Calculate also the minimum period using a rounded refresh rate
// This will be used only for display purposes, so that FPS are capped
// to 60 Hz rather than 59.83 Hz, which would be the hw-accurate value.
min_refresh_period_rounded = 1.0f / (fps ? fps : roundf(refresh_rate));
min_refresh_period_rounded = 1.0f / (fps ? MIN(fps, roundf(refresh_rate)) : roundf(refresh_rate));

enable_interrupts();
}
Expand Down

0 comments on commit 4f21412

Please sign in to comment.