Skip to content

Add nullptr check for pTFAttacker #1379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kenzzer
Copy link

@Kenzzer Kenzzer commented Jun 24, 2025

Description

This fixes a very rare crash in

void EconItemInterface_OnOwnerKillEaterEvent_Batched( IEconItemInterface *pEconInterface, class CTFPlayer *pOwner, class CTFPlayer *pVictim, kill_eater_event_t eEventType, int nIncrementValue /*= 1*/ )
{
for ( int i = 0; i < pOwner->GetNumWearables(); ++i )

As you can see pOwner is never null checked for. And in very rare instances

CTFWeaponBase *pTFWeapon = GetKilleaterWeaponFromDamageInfo( &info );
if ( !pTFWeapon )
{
// Check Wearable instead like demoshields or manntreads
CTFWearable *pWearable = dynamic_cast< CTFWearable* >( info.GetWeapon() );
if ( pWearable )
{
EconEntity_OnOwnerKillEaterEvent_Batched( pWearable, pTFAttacker, this, kKillEaterEvent_DamageDealt, info.GetDamage() );
EconEntity_OnOwnerKillEaterEvent_Batched( pWearable, pTFAttacker, this, kKillEaterEvent_PlayersHit, 1 );
}
}
else
{
EconEntity_OnOwnerKillEaterEvent_Batched( pTFWeapon, pTFAttacker, this, kKillEaterEvent_DamageDealt, info.GetDamage() );
EconEntity_OnOwnerKillEaterEvent_Batched( pTFWeapon, pTFAttacker, this, kKillEaterEvent_PlayersHit, 1 );
}

That function is called when pTFAttacker is nullptr.

Since pTFAttacker is already null-checked in lot of places inside int CTFPlayer::OnTakeDamage( const CTakeDamageInfo &inputInfo ) let's just add one extra check there (see PR changes).

Bitl added a commit to BitlDevelopmentStudios/source-sdk-2013-bds-base that referenced this pull request Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant