From 8ba5efc31b0d66ed2523bc7673eb4ebc8cbf4b42 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 24 Jan 2004 19:05:54 +0000 Subject: [PATCH] fix BGChange crash --- stepmania/src/Background.cpp | 24 ++++++++++++------------ stepmania/src/Background.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index 96730d64d7..d69e34b5c0 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -116,7 +116,7 @@ void Background::Unload() m_pFadingBGA = NULL; m_pSong = NULL; m_fSecsLeftInFade = 0; - m_iCurBGChangeIndex = 0; + m_iCurBGChangeIndex = -1; m_fLastMusicSeconds = -9999; } @@ -393,14 +393,14 @@ void Background::LoadFromSong( const Song* pSong ) LoadFromRandom( fStartBeat, fLastBeat, pSong->m_Timing ); } + // At this point, we shouldn't have any BGChanges to "". "" is an invalid name. + for( i=0; im_SongOptions.m_fMusicRate; - - for( map::iterator iter = m_BGAnimations.begin(); iter != m_BGAnimations.end(); iter++ ) @@ -431,7 +431,7 @@ void Background::LoadFromSong( const Song* pSong ) m_pDancingCharacters->LoadNextSong(); } -int Background::FindBPMSegmentForBeat( float fBeat ) const +int Background::FindBGSegmentForBeat( float fBeat ) const { int i; for( i=0; i<(int)(m_aBGChanges.size()) - 1; i++ ) @@ -454,13 +454,13 @@ void Background::UpdateCurBGChange( float fCurrentTime ) bool bFreeze; m_pSong->m_Timing.GetBeatAndBPSFromElapsedTime( fCurrentTime, fBeat, fBPS, bFreeze ); - // Find the BGSegment we're in - const int i = FindBPMSegmentForBeat( fBeat ); - /* Calls to Update() should *not* be scaled by music rate; fCurrentTime is. Undo it. */ const float fRate = GAMESTATE->m_SongOptions.m_fMusicRate; - if( i != m_iCurBGChangeIndex ) + // Find the BGSegment we're in + const int i = FindBGSegmentForBeat( fBeat ); + + if( i != -1 && i != m_iCurBGChangeIndex ) // we're changing backgrounds { LOG->Trace( "old bga %d -> new bga %d, %f, %f", i, m_iCurBGChangeIndex, m_aBGChanges[i].m_fStartBeat, fBeat ); @@ -493,7 +493,7 @@ void Background::UpdateCurBGChange( float fCurrentTime ) if( m_pCurrentBGA ) m_pCurrentBGA->Update( fDeltaTime ); } - else + else // we're not changing backgrounds { /* This is affected by the music rate. */ float fDeltaTime = fCurrentTime - m_fLastMusicSeconds; diff --git a/stepmania/src/Background.h b/stepmania/src/Background.h index d0418aa35a..e7d3912ac6 100644 --- a/stepmania/src/Background.h +++ b/stepmania/src/Background.h @@ -42,7 +42,7 @@ protected: const Song *m_pSong; void LoadFromAniDir( CString sAniDir ); void LoadFromRandom( float fFirstBeat, float fLastBeat, const TimingData &timing ); - int FindBPMSegmentForBeat( float fBeat ) const; + int FindBGSegmentForBeat( float fBeat ) const; bool IsDangerPlayerVisible( PlayerNumber pn ); bool IsDangerAllVisible();