diff options
Diffstat (limited to 'mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp')
| -rw-r--r-- | mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp b/mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp index 975eec17..4d1ad4fe 100644 --- a/mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp +++ b/mp/src/game/shared/Multiplayer/multiplayer_animstate.cpp @@ -358,16 +358,21 @@ void CMultiPlayerAnimState::PlayFlinchGesture( Activity iActivity ) //----------------------------------------------------------------------------- bool CMultiPlayerAnimState::InitGestureSlots( void ) { - // Get the base player. - CBasePlayer *pPlayer = GetBasePlayer(); - if( pPlayer ) + // Setup the number of gesture slots. + m_aGestureSlots.AddMultipleToTail( GESTURE_SLOT_COUNT ); + + // Assign all of the the CAnimationLayer pointers to null early in case we bail. + for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture ) { - // Set the number of animation overlays we will use. - pPlayer->SetNumAnimOverlays( GESTURE_SLOT_COUNT ); + m_aGestureSlots[iGesture].m_pAnimLayer = NULL; } - // Setup the number of gesture slots. - m_aGestureSlots.AddMultipleToTail( GESTURE_SLOT_COUNT ); + // Get the base player. + CBasePlayer *pPlayer = GetBasePlayer(); + + // Set the number of animation overlays we will use. + pPlayer->SetNumAnimOverlays( GESTURE_SLOT_COUNT ); + for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture ) { m_aGestureSlots[iGesture].m_pAnimLayer = pPlayer->GetAnimOverlay( iGesture ); @@ -409,6 +414,9 @@ void CMultiPlayerAnimState::ResetGestureSlot( int iGestureSlot ) // Sanity Check Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT ); + if ( !VerifyAnimLayerInSlot( iGestureSlot ) ) + return; + GestureSlot_t *pGestureSlot = &m_aGestureSlots[iGestureSlot]; if ( pGestureSlot ) { @@ -486,6 +494,36 @@ bool CMultiPlayerAnimState::IsGestureSlotActive( int iGestureSlot ) return m_aGestureSlots[iGestureSlot].m_bActive; } + +//----------------------------------------------------------------------------- +// Purpose: Track down a crash +//----------------------------------------------------------------------------- +bool CMultiPlayerAnimState::VerifyAnimLayerInSlot( int iGestureSlot ) +{ + if ( iGestureSlot < 0 || iGestureSlot >= GESTURE_SLOT_COUNT ) + { + return false; + } + + if ( GetBasePlayer()->GetNumAnimOverlays() < iGestureSlot + 1 ) + { + AssertMsg2( false, "Player %d doesn't have gesture slot %d any more.", GetBasePlayer()->entindex(), iGestureSlot ); + Msg( "Player %d doesn't have gesture slot %d any more.\n", GetBasePlayer()->entindex(), iGestureSlot ); + m_aGestureSlots[iGestureSlot].m_pAnimLayer = NULL; + return false; + } + + CAnimationLayer *pExpected = GetBasePlayer()->GetAnimOverlay( iGestureSlot ); + if ( m_aGestureSlots[iGestureSlot].m_pAnimLayer != pExpected ) + { + AssertMsg3( false, "Gesture slot %d pointing to wrong address %p. Updating to new address %p.", iGestureSlot, m_aGestureSlots[iGestureSlot].m_pAnimLayer, pExpected ); + Msg( "Gesture slot %d pointing to wrong address %p. Updating to new address %p.\n", iGestureSlot, m_aGestureSlots[iGestureSlot].m_pAnimLayer, pExpected ); + m_aGestureSlots[iGestureSlot].m_pAnimLayer = pExpected; + } + + return true; +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -509,6 +547,9 @@ void CMultiPlayerAnimState::RestartGesture( int iGestureSlot, Activity iGestureA // Sanity Check Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT ); + if ( !VerifyAnimLayerInSlot( iGestureSlot ) ) + return; + if ( !IsGestureSlotPlaying( iGestureSlot, iGestureActivity ) ) { #ifdef CLIENT_DLL @@ -549,6 +590,9 @@ void CMultiPlayerAnimState::AddToGestureSlot( int iGestureSlot, Activity iGestur if ( !m_aGestureSlots[iGestureSlot].m_pAnimLayer ) return; + if ( !VerifyAnimLayerInSlot( iGestureSlot ) ) + return; + // Get the sequence. int iGestureSequence = pPlayer->SelectWeightedSequence( iGestureActivity ); if ( iGestureSequence <= 0 ) @@ -623,6 +667,9 @@ void CMultiPlayerAnimState::AddVCDSequenceToGestureSlot( int iGestureSlot, int i if ( !m_aGestureSlots[iGestureSlot].m_pAnimLayer ) return; + if ( !VerifyAnimLayerInSlot( iGestureSlot ) ) + return; + // Set the activity. Activity iGestureActivity = ACT_MP_VCD; @@ -1154,6 +1201,9 @@ void CMultiPlayerAnimState::ComputeGestureSequence( CStudioHdr *pStudioHdr ) if ( !m_aGestureSlots[iGesture].m_bActive ) continue; + if ( !VerifyAnimLayerInSlot( iGesture ) ) + continue; + UpdateGestureLayer( pStudioHdr, &m_aGestureSlots[iGesture] ); } } |