diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 23a65e403..0af149fbc 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -262,6 +262,13 @@ namespace hex { const auto targetFrameTime = 1.0 / targetFPS; if (frameTime < targetFrameTime) { glfwWaitEventsTimeout(targetFrameTime - frameTime); + + // glfwWaitEventsTimeout might return early if there's an event + const auto frameTime = glfwGetTime() - m_lastStartFrameTime; + if (frameTime < targetFrameTime) { + const auto timeToSleepMs = (int)((targetFrameTime - frameTime) * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(timeToSleepMs)); + } } } }