From 4298f2542de88b133109c28e117b368595d39075 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 2 Nov 2013 04:11:30 -0400 Subject: [PATCH] Check MakeActor rvs for NULL --- src/ActorUtil.cpp | 2 ++ src/BGAnimationLayer.cpp | 2 ++ src/Background.cpp | 3 ++- src/ComboGraph.cpp | 33 +++++++++++++++++++++++---------- src/Foreground.cpp | 2 ++ src/OptionRow.cpp | 5 ++++- src/ScreenHighScores.cpp | 3 ++- src/ScreenManager.cpp | 7 +++++-- 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/ActorUtil.cpp b/src/ActorUtil.cpp index 4892483342..5c41e6804e 100644 --- a/src/ActorUtil.cpp +++ b/src/ActorUtil.cpp @@ -201,6 +201,8 @@ bool ActorUtil::LoadTableFromStackShowErrors( Lua *L ) return true; } +// NOTE: This function can return NULL if the actor should not be displayed. +// Callers should be aware of this and handle it appropriately. Actor* ActorUtil::MakeActor( const RString &sPath_, Actor *pParentActor ) { RString sPath( sPath_ ); diff --git a/src/BGAnimationLayer.cpp b/src/BGAnimationLayer.cpp index d65e9ae3fc..a30e9a880c 100644 --- a/src/BGAnimationLayer.cpp +++ b/src/BGAnimationLayer.cpp @@ -520,6 +520,8 @@ void BGAnimationLayer::LoadFromNode( const XNode* pNode ) for( unsigned i=0; iAddChild( pSprite ); pSprite->SetTextureWrapping( true ); // gets rid of some "cracks" pSprite->SetZoom( randomf(fZoomMin,fZoomMax) ); diff --git a/src/Background.cpp b/src/Background.cpp index e077454f31..da9d5d73f8 100644 --- a/src/Background.cpp +++ b/src/Background.cpp @@ -373,7 +373,8 @@ bool BackgroundImpl::Layer::CreateBackground( const Song *pSong, const Backgroun Actor *pActor = ActorUtil::MakeActor( sEffectFile ); - ASSERT( pActor != NULL ); + if( pActor == NULL ) + pActor = new Actor; m_BGAnimations[bd] = pActor; for( unsigned i=0; iGetPathG(sMetricsGroup,"Backing") ); - m_pBacking->ZoomToWidth( BODY_WIDTH ); - this->AddChild( m_pBacking ); + if( m_pBacking != NULL ) + { + m_pBacking->ZoomToWidth( BODY_WIDTH ); + this->AddChild( m_pBacking ); + } m_pNormalCombo = ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"NormalCombo") ); - m_pNormalCombo->ZoomToWidth( BODY_WIDTH ); - this->AddChild( m_pNormalCombo ); + if( m_pNormalCombo != NULL ) + { + m_pNormalCombo->ZoomToWidth( BODY_WIDTH ); + this->AddChild( m_pNormalCombo ); + } m_pMaxCombo = ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"MaxCombo") ); - m_pMaxCombo->ZoomToWidth( BODY_WIDTH ); - this->AddChild( m_pMaxCombo ); + if( m_pMaxCombo != NULL ) + { + m_pMaxCombo->ZoomToWidth( BODY_WIDTH ); + this->AddChild( m_pMaxCombo ); + } pActor = ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"ComboNumber") ); - m_pComboNumber = dynamic_cast( pActor ); - if( m_pComboNumber == NULL ) - RageException::Throw( "ComboGraph: \"sMetricsGroup\" \"ComboNumber\" must be a BitmapText" ); - this->AddChild( m_pComboNumber ); + if( pActor != NULL ) + { + m_pComboNumber = dynamic_cast( pActor ); + if( m_pComboNumber != NULL ) + this->AddChild( m_pComboNumber ); + else + LOG->Warn( "ComboGraph: \"sMetricsGroup\" \"ComboNumber\" must be a BitmapText" ); + } } void ComboGraph::Set( const StageStats &s, const PlayerStageStats &pss ) diff --git a/src/Foreground.cpp b/src/Foreground.cpp index 173bd353e6..fdfed2a955 100644 --- a/src/Foreground.cpp +++ b/src/Foreground.cpp @@ -45,6 +45,8 @@ void Foreground::LoadFromSong( const Song *pSong ) { bga.m_bga = ActorUtil::MakeActor( pSong->GetSongDir() + sBGName, this ); } + if( bga.m_bga == NULL ) + continue; bga.m_bga->SetName( sBGName ); bga.m_bga->PlayCommand( "Init" ); bga.m_fStartBeat = change.m_fStartBeat; diff --git a/src/OptionRow.cpp b/src/OptionRow.cpp index 7bc94053b9..030cdfcd94 100644 --- a/src/OptionRow.cpp +++ b/src/OptionRow.cpp @@ -107,7 +107,10 @@ void OptionRowType::Load( const RString &sMetricsGroup, Actor *pParent ) m_textTitle.SetName( "Title" ); ActorUtil::LoadAllCommandsAndSetXY( m_textTitle, sMetricsGroup ); - m_sprFrame.Load( ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"Frame"), pParent ) ); + Actor *pActor = ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"Frame"), pParent ); + if( pActor == NULL ) + pActor = new Actor; + m_sprFrame.Load( pActor ); m_sprFrame->SetName( "Frame" ); ActorUtil::LoadAllCommandsAndSetXY( m_sprFrame, sMetricsGroup ); diff --git a/src/ScreenHighScores.cpp b/src/ScreenHighScores.cpp index 0eb134f199..5dc17180dc 100644 --- a/src/ScreenHighScores.cpp +++ b/src/ScreenHighScores.cpp @@ -187,7 +187,8 @@ void ScoreScroller::Load( RString sMetricsGroup ) for( int i=0; iGetPathG(sMetricsGroup,"ScrollerItem") ); - this->AddChild( pActor ); + if( pActor != NULL ) + this->AddChild( pActor ); } DynamicActorScroller::SetTransformFromReference( THEME->GetMetricR(sMetricsGroup,"ScrollerItemTransformFunction") ); diff --git a/src/ScreenManager.cpp b/src/ScreenManager.cpp index 842a29b2f9..a626ef90a8 100644 --- a/src/ScreenManager.cpp +++ b/src/ScreenManager.cpp @@ -584,8 +584,11 @@ void ScreenManager::PrepareScreen( const RString &sScreenName ) { LOG->Trace( "Loading screen background \"%s\"", sNewBGA.c_str() ); Actor *pActor = ActorUtil::MakeActor( sNewBGA ); - pActor->SetName( sNewBGA ); - g_vPreparedBackgrounds.push_back( pActor ); + if( pActor != NULL ) + { + pActor->SetName( sNewBGA ); + g_vPreparedBackgrounds.push_back( pActor ); + } } }