From 884e3fd21ff73275affd4d01fcc01b5a176ce533 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 12 Jun 2023 11:58:17 +0200 Subject: [PATCH] Backends: GLFW: Accept glfwGetTime() not returning a monotonically increasing value. (#6491, #6189, #6114) --- backends/imgui_impl_glfw.cpp | 4 ++++ docs/CHANGELOG.txt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 31b22681..0858cddb 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -17,6 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-06-12: Accept glfwGetTime() not returning a monotonically increasing value. This seems to happens on some Windows setup when peripherals disconnect, and is likely to also happen on browser + Emscripten. (#6491) // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen on Windows ONLY, using a custom WndProc hook. (#2702) // 2023-03-16: Inputs: Fixed key modifiers handling on secondary viewports (docking branch). Broken on 2023/01/04. (#6248, #6034) // 2023-03-14: Emscripten: Avoid using glfwGetError() and glfwGetGamepadState() which are not correctly implemented in Emscripten emulation. (#6240) @@ -780,7 +781,10 @@ void ImGui_ImplGlfw_NewFrame() io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h); // Setup time step + // (Accept glfwGetTime() not returning a monotonically increasing value. Seems to happens on disconnecting peripherals and probably on VMs and Emscripten, see #6491, #6189, #6114, #3644) double current_time = glfwGetTime(); + if (current_time <= bd->Time) + current_time = bd->Time + 0.00001f; io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f); bd->Time = current_time; diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e5fef676..20c1740a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,9 @@ Other changes: - Tables: Fixed a regression in 1.89.6 leading to the first column of tables with either ScrollX or ScrollY flags from being impossible to resize. (#6503) - Backends: OpenGL3: Fixed support for glBindSampler() backup/restore on ES3. (#6375, #6508) [@jsm174] +- Backends: GLFW: Accept glfwGetTime() not returning a monotonically increasing value. + This seems to happens on some Windows setup when peripherals disconnect, and is likely + to also happen on browser+Emscripten. Matches similar 1.89.4 fix in SDL backend. (#6491) -----------------------------------------------------------------------