From 515a4d07fb262ceaada16271ca289d9c7e3a128a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 22 Dec 2024 14:43:38 +1000 Subject: [PATCH] System: Fix pre-frame sleep getting stuck --- src/core/system.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index 72b0ec1c3..1a76ed665 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -2120,16 +2120,20 @@ void System::FrameDone() AccumulatePreFrameSleepTime(current_time); // pre-frame sleep (input lag reduction) - current_time = Timer::GetCurrentValue(); - if (s_state.pre_frame_sleep) + // if we're running over, then fall through to the normal Throttle() case which will fix up next_frame_time. + if (s_state.pre_frame_sleep && pre_frame_sleep_until > current_time) { // don't sleep if it's under 1ms, because we're just going to overshoot (or spin). - if (pre_frame_sleep_until > current_time && - Timer::ConvertValueToMilliseconds(pre_frame_sleep_until - current_time) >= 1) + if (Timer::ConvertValueToMilliseconds(pre_frame_sleep_until - current_time) >= 1) { Throttle(current_time, pre_frame_sleep_until); current_time = Timer::GetCurrentValue(); } + else + { + // still need to update next_frame_time + s_state.next_frame_time += s_state.frame_period; + } } else {