Skip to content

Commit

Permalink
[server] Fix infinite loops and null dereference when CSoundEnt::Soun…
Browse files Browse the repository at this point in the history
…dPointerForIndex is nullptr
  • Loading branch information
dimhotepus committed Dec 9, 2024
1 parent 393c18a commit 5fd74bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 8 additions & 3 deletions game/server/ai_basenpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,11 +3202,11 @@ void CAI_BaseNPC::UpdateEfficiency( bool bInPVS )
{
CSound *pCurrentSound = CSoundEnt::SoundPointerForIndex( iSound );

float hearingSensitivity = HearingSensitivity();
Vector vEarPosition = EarPosition();

if ( pCurrentSound && (SOUND_DANGER & pCurrentSound->SoundType()) )
{
float hearingSensitivity = HearingSensitivity();
Vector vEarPosition = EarPosition();

float flHearDistanceSq = pCurrentSound->Volume() * hearingSensitivity;
flHearDistanceSq *= flHearDistanceSq;
if ( pCurrentSound->GetSoundOrigin().DistToSqr( vEarPosition ) <= flHearDistanceSq )
Expand All @@ -3220,6 +3220,11 @@ void CAI_BaseNPC::UpdateEfficiency( bool bInPVS )
{
iSound = pCurrentSound->NextSound();
}
else
{
// dimhotepus: Break if no current sound.
break;
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion game/server/ai_senses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ void CAI_Senses::Listen( void )
m_iAudibleList = iSound;
}

iSound = pCurrentSound->NextSound();
if ( pCurrentSound )
{
iSound = pCurrentSound->NextSound();
}
else
{
// dimhotepus: Break if no current sound.
break;
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions game/server/envmicrophone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,14 @@ void CEnvMicrophone::Think(void)
fHearSound = true;
}
}
}

nSound = pCurrentSound->NextSound();
nSound = pCurrentSound->NextSound();
}
else
{
// dimhotepus: Break if no current sound.
break;
}
}

if( fHearSound )
Expand Down

0 comments on commit 5fd74bf

Please sign in to comment.