Skip to content

Commit 6fbbf89

Browse files
authored
fix: Frame rate getting unlocked when inputs are being processed (#1632)
### Problem description The framerate limiter doesn't work when inputs are being sent (eg mouse cursor moving over the window), because `glfwWaitEventsTimeout` returns early when it encounters an event. ### Implementation description I made it sleep for the remaining time when that happens.
1 parent 1df0eea commit 6fbbf89

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

main/gui/source/window/window.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ namespace hex {
262262
const auto targetFrameTime = 1.0 / targetFPS;
263263
if (frameTime < targetFrameTime) {
264264
glfwWaitEventsTimeout(targetFrameTime - frameTime);
265+
266+
// glfwWaitEventsTimeout might return early if there's an event
267+
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
268+
if (frameTime < targetFrameTime) {
269+
const auto timeToSleepMs = (int)((targetFrameTime - frameTime) * 1000);
270+
std::this_thread::sleep_for(std::chrono::milliseconds(timeToSleepMs));
271+
}
265272
}
266273
}
267274
}

0 commit comments

Comments
 (0)