From f0c679fb6101119f3fe758cff68bd68e16240f56 Mon Sep 17 00:00:00 2001 From: wardwouts Date: Sat, 4 Dec 2021 23:16:15 +0100 Subject: [PATCH] fix: Crash when framerate falls below 5 FPS (#359) * This could work * Testing shows this to work fine, with the added benefit of lower CPU usage * This should do the trick then --- source/window/window.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/window/window.cpp b/source/window/window.cpp index 0cb47cdb0..18ca41511 100644 --- a/source/window/window.cpp +++ b/source/window/window.cpp @@ -279,13 +279,15 @@ namespace hex { } void Window::loop() { + double timeout; this->m_lastFrameTime = glfwGetTime(); while (!glfwWindowShouldClose(this->m_window)) { if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED)) glfwWaitEvents(); else - glfwWaitEventsTimeout(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) ? 0 : (this->m_lastFrameTime - glfwGetTime() + 1 / 5.0)); - + timeout = (1.0 / 5.0) - (glfwGetTime() - this->m_lastFrameTime); + timeout = timeout > 0 ? timeout : 0; + glfwWaitEventsTimeout(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) ? 0 : timeout); this->frameBegin(); this->frame();