From 3913f97cd32b66e3ed5947c191801dfb5d9f79f2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 10 Apr 2007 21:12:33 +0000 Subject: [PATCH] fix crash when queued commands finishtweening/stoptweening --- stepmania/src/Actor.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index e6afac2e92..23b679c73b 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -543,23 +543,15 @@ void Actor::UpdateTweening( float fDeltaTime ) TweenState &TS = m_Tweens[0]->state; TweenInfo &TI = m_Tweens[0]->info; - if( TI.m_fTimeLeftInTween == TI.m_fTweenTime ) // we are just beginning this tween - { - m_start = m_current; // set the start position - - // Execute the command in this tween (if any). - if( !TI.m_sCommandName.empty() ) - { - if( TI.m_sCommandName.Left(1) == "!" ) - MESSAGEMAN->Broadcast( TI.m_sCommandName.substr(1) ); - else - this->PlayCommand( TI.m_sCommandName ); - } - } + bool bBeginning = TI.m_fTimeLeftInTween == TI.m_fTweenTime; float fSecsToSubtract = min( TI.m_fTimeLeftInTween, fDeltaTime ); TI.m_fTimeLeftInTween -= fSecsToSubtract; fDeltaTime -= fSecsToSubtract; + + RString sCommand = TI.m_sCommandName; + if( bBeginning ) // we are just beginning this tween + m_start = m_current; // set the start position if( TI.m_fTimeLeftInTween == 0 ) // Current tween is over. Stop. { @@ -577,6 +569,19 @@ void Actor::UpdateTweening( float fDeltaTime ) float fPercentAlongPath = TI.m_pTween->Tween( fPercentThroughTween ); TweenState::MakeWeightedAverage( m_current, m_start, TS, fPercentAlongPath ); } + + if( bBeginning ) + { + // Execute the command in this tween (if any). Do this last, and don't access + // TI or TS after, since this may modify the tweening queue. + if( !sCommand.empty() ) + { + if( sCommand.Left(1) == "!" ) + MESSAGEMAN->Broadcast( sCommand.substr(1) ); + else + this->PlayCommand( sCommand ); + } + } } }