From 29adeae6a31a37f0a8703f3d1d212ea546414559 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 15 Aug 2022 22:21:53 +0200 Subject: [PATCH] fix: Undefined behaviour in frame wait time calculation --- main/source/window/window.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index c2ec7a381..395710e3f 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -202,8 +202,11 @@ namespace hex { this->frameEnd(); const auto targetFps = ImHexApi::System::getTargetFPS(); - if (targetFps <= 200) - std::this_thread::sleep_for(std::chrono::milliseconds(u64((this->m_lastFrameTime + 1 / targetFps - glfwGetTime()) * 1000))); + if (targetFps <= 200) { + auto leftoverFrameTime = i64((this->m_lastFrameTime + 1 / targetFps - glfwGetTime()) * 1000); + if (leftoverFrameTime > 0) + std::this_thread::sleep_for(std::chrono::milliseconds(leftoverFrameTime)); + } this->m_lastFrameTime = glfwGetTime();