From cc259f9a34974dcef4d126dfd3277e0a8c9a180c Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 12 Oct 2023 14:07:55 +0400 Subject: frame_clock: Defend against last presentation time being too much in the future --- src/frame_clock.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/frame_clock.rs b/src/frame_clock.rs index f7f55890..ad8cf2f7 100644 --- a/src/frame_clock.rs +++ b/src/frame_clock.rs @@ -52,8 +52,19 @@ impl FrameClock { if now <= last_presentation_time { // Got an early VBlank. + let orig_now = now; now += Duration::from_nanos(refresh_interval_ns); - // Assume two-frame early VBlanks don't happen. Overflow checks will catch them. + + if now < last_presentation_time { + // Not sure when this can happen. + error!( + now = ?orig_now, + ?last_presentation_time, + "got a 2+ early VBlank, {:?} until presentation", + last_presentation_time - now, + ); + now = last_presentation_time + Duration::from_nanos(refresh_interval_ns); + } } let since_last = now - last_presentation_time; -- cgit