Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfixed bizzare non-monotonically-increasing SDL_GetPerformanceCounter bug #6189

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backends/imgui_impl_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ void ImGui_ImplSDL2_NewFrame()
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 current_time = SDL_GetPerformanceCounter();

// If SDL_GetPerformanceCounter doesn't return a monotonically increasing value,
// "fake" the time this frame.
//
// This bizzare edge-case bug seems to happen when using the SDL backend in a VirtualBox
// VM, it also seems to happen in emscripten backends (#6114, #3644) - might be related to
// a Spectre mitigation?
if (current_time <= bd->Time)
{
current_time = bd->Time + 1;
}
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
bd->Time = current_time;

Expand Down