From c6125c4e269d5d3878b3abe01ab976aa539cb8ce Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 25 Feb 2006 10:08:18 +0000 Subject: [PATCH] Actor.cpp "fDeltaTime >= 0" assertion fires occasionally. This is under Foreground's update, caused by GAMESTATE->m_fMusicSeconds moving backwards. This happens due to frame skips confusing GameSoundManager::GetFrameTimingAdjustment. It expects that, when the framerate is stable, each frame will take 1/FPS. If we skip a frame, it thinks one frame is 30ms late, and tries to adjust by 30-16ms. Reduce the threshold for this adjustment to half a frame; if we're that much late, the problem isn't scheduling jitter--we've probably dropped a frame, and adjusting here is incorrect. In case that isn't enough, clamp fDeltaTime in Foreground, too. --- stepmania/src/Foreground.cpp | 4 ++++ stepmania/src/GameSoundManager.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/stepmania/src/Foreground.cpp b/stepmania/src/Foreground.cpp index 68cde9553f..bbe205dfe5 100644 --- a/stepmania/src/Foreground.cpp +++ b/stepmania/src/Foreground.cpp @@ -88,6 +88,10 @@ void Foreground::Update( float fDeltaTime ) { fDeltaTime = GAMESTATE->m_fMusicSeconds - m_fLastMusicSeconds; } + + /* This shouldn't go down, but be safe: */ + fDeltaTime = max( fDeltaTime, 0 ); + bga.m_bga->Update( fDeltaTime / fRate ); if( GAMESTATE->m_fSongBeat > bga.m_fStopBeat ) diff --git a/stepmania/src/GameSoundManager.cpp b/stepmania/src/GameSoundManager.cpp index 42d40f2266..017ddb58d0 100644 --- a/stepmania/src/GameSoundManager.cpp +++ b/stepmania/src/GameSoundManager.cpp @@ -441,7 +441,7 @@ float GameSoundManager::GetFrameTimingAdjustment( float fDeltaTime ) const float fExpectedDelay = 1.0f / iThisFPS; const float fExtraDelay = fDeltaTime - fExpectedDelay; - if( fabsf(fExtraDelay) >= fExpectedDelay ) + if( fabsf(fExtraDelay) >= fExpectedDelay/2 ) return 0; /* Subtract the extra delay. */