From 07490618ae47fdb9f625565fbb183593170a6a72 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 25 Jan 2023 14:13:12 +0100 Subject: [PATCH] Misc: Tolerate zero delta-time under Emscripten. (#6114, #3644) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6c19b78a..df9f554e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -51,6 +51,9 @@ All changes: - PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. - ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when color alpha is zero. +- Misc: Tolerate zero delta-time under Emscripten as backends are imprecise in their + values for io.DeltaTime, and browser features such as "privacy.resistFingerprinting=true" + can exacerbate that. (#6114, #3644) - Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx] diff --git a/imgui.cpp b/imgui.cpp index df8b1dc4..da04669e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8852,6 +8852,13 @@ static void ImGui::ErrorCheckNewFrameSanityChecks() // #define IM_ASSERT(EXPR) do { if (SomeCode(EXPR)) SomeMoreCode(); } while (0) // Correct! if (true) IM_ASSERT(1); else IM_ASSERT(0); + // Emscripten backends are often imprecise in their submission of DeltaTime. (#6114, #3644) + // Ideally the Emscripten app/backend should aim to fix or smooth this value and avoid feeding zero, but we tolerate it. +#ifdef __EMSCRIPTEN__ + if (g.IO.DeltaTime <= 0.0f && g.FrameCount > 0) + g.IO.DeltaTime = 0.00001f; +#endif + // Check user data // (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument) IM_ASSERT(g.Initialized);