Fix crash in Background if CreateRandomBG fails

This commit is contained in:
Chris Danford
2003-03-16 07:20:37 +00:00
parent ee10a98b35
commit 8b7894be76
2 changed files with 29 additions and 10 deletions
+28 -6
View File
@@ -229,11 +229,17 @@ void Background::LoadFromSong( Song* pSong )
// Load random backgrounds
bool bLoadedAnyRandomBackgrounds = false;
{
for( int i=0; i<MAX_RANDOM_BACKGROUNDS; i++ )
{
CString sBGName = RANDOM_BACKGROUND[ i ];
m_BGAnimations[sBGName] = CreateRandomBGA();
BGAnimation *pTempBGA = CreateRandomBGA();
if( pTempBGA )
{
m_BGAnimations[sBGName] = pTempBGA;
bLoadedAnyRandomBackgrounds = true;
}
}
}
@@ -257,7 +263,10 @@ void Background::LoadFromSong( Song* pSong )
if( pTempBGA )
m_BGAnimations[sBGName] = pTempBGA;
else // the background was not found. Use a random one instead
sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
if( bLoadedAnyRandomBackgrounds )
sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
else
sBGName = STATIC_BACKGROUND;
}
m_aBGChanges.push_back( BackgroundChange(fStartBeat, sBGName) );
@@ -271,8 +280,11 @@ void Background::LoadFromSong( Song* pSong )
// change BG every 4 bars
for( float f=fFirstBeat; f<fLastBeat; f+=BEATS_PER_MEASURE*4 )
{
CString sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
m_aBGChanges.push_back( BackgroundChange(f,sBGName) );
if( bLoadedAnyRandomBackgrounds )
{
CString sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
m_aBGChanges.push_back( BackgroundChange(f,sBGName) );
}
}
// change BG every BPM change that is at the beginning of a measure
@@ -286,8 +298,11 @@ void Background::LoadFromSong( Song* pSong )
if( bpmseg.m_fStartBeat < fFirstBeat || bpmseg.m_fStartBeat > fLastBeat )
continue; // skip
CString sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
m_aBGChanges.push_back( BackgroundChange(bpmseg.m_fStartBeat,sBGName) );
if( bLoadedAnyRandomBackgrounds )
{
CString sBGName = RANDOM_BACKGROUND[ rand()%MAX_RANDOM_BACKGROUNDS ];
m_aBGChanges.push_back( BackgroundChange(bpmseg.m_fStartBeat,sBGName) );
}
}
}
@@ -411,3 +426,10 @@ void Background::FadeOut()
m_quadBGBrightness.SetTweenDiffuse( RageColor(0,0,0,1-0.5f) );
}
BGAnimation* Background::GetCurrentBGA()
{
CString sBGName = m_aBGChanges[m_iCurBGChange].m_sBGName;
ASSERT( m_BGAnimations[ sBGName ] );
return m_BGAnimations[ sBGName ];
}
+1 -4
View File
@@ -53,10 +53,7 @@ protected:
map<CString,BGAnimation*> m_BGAnimations;
vector<BackgroundChange> m_aBGChanges;
int m_iCurBGChange; // starts at 0 and increases to m_aBGSegments.size()-1
BGAnimation* GetCurrentBGA()
{
return m_BGAnimations[ m_aBGChanges[m_iCurBGChange].m_sBGName ];
}
BGAnimation* GetCurrentBGA();
BGAnimation* m_pFadingBGA;
float m_fSecsLeftInFade;