Skip to content

Commit c390144

Browse files
committed
Add asserts to identify the source of a ped related crash
1 parent a389d52 commit c390144

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,7 +4279,10 @@ bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent)
42794279
SClientEntity<CPedSA>* pPedClientEntity = pPools->GetPed((DWORD*)pDamagePed->GetInterface());
42804280
if (pPedClientEntity)
42814281
{
4282+
assert(pPedClientEntity->pEntity != nullptr);
4283+
assert(pPedClientEntity->pClientEntity != nullptr);
42824284
pDamagedPed = reinterpret_cast<CClientPed*>(pPedClientEntity->pClientEntity);
4285+
assert(pDamagedPed->GetGamePlayer() != nullptr);
42834286
}
42844287
}
42854288

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,10 @@ void CClientPed::_CreateModel()
35843584
m_pLoadedModelInfo->ModelAddRef(BLOCKING, "CClientPed::_CreateModel");
35853585

35863586
// Create the new ped
3587-
m_pPlayerPed = dynamic_cast<CPlayerPed*>(g_pGame->GetPools()->AddPed(this, static_cast<ePedModel>(m_ulModel)));
3587+
CPed* gamePed = g_pGame->GetPools()->AddPed(this, static_cast<ePedModel>(m_ulModel));
3588+
m_pPlayerPed = dynamic_cast<CPlayerPed*>(gamePed);
3589+
assert(gamePed == nullptr && m_pPlayerPed == nullptr || gamePed != nullptr && m_pPlayerPed != nullptr);
3590+
35883591
if (m_pPlayerPed)
35893592
{
35903593
// Put our pointer in the stored data and update the remote data with the new model pointer
@@ -3708,7 +3711,10 @@ void CClientPed::_CreateLocalModel()
37083711
{
37093712
// Init the local player and grab the pointers
37103713
g_pGame->InitLocalPlayer(this);
3711-
m_pPlayerPed = dynamic_cast<CPlayerPed*>(g_pGame->GetPools()->GetPedFromRef((DWORD)1));
3714+
3715+
CPed* gamePed = g_pGame->GetPools()->GetPedFromRef((DWORD)1);
3716+
m_pPlayerPed = dynamic_cast<CPlayerPed*>(gamePed);
3717+
assert(gamePed == nullptr && m_pPlayerPed == nullptr || gamePed != nullptr && m_pPlayerPed != nullptr);
37123718

37133719
if (m_pPlayerPed)
37143720
{
@@ -3806,10 +3812,17 @@ void CClientPed::_DestroyModel()
38063812
// Invalidate
38073813
m_pManager->InvalidateEntity(this);
38083814

3815+
// Store the amount of peds in the ped pool before removal
3816+
unsigned long const previousPedCount = g_pGame->GetPools()->GetPedCount();
3817+
38093818
// Remove the ped from the world
38103819
g_pGame->GetPools()->RemovePed(m_pPlayerPed);
3811-
m_pPlayerPed = NULL;
3812-
m_pTaskManager = NULL;
3820+
m_pPlayerPed = nullptr;
3821+
m_pTaskManager = nullptr;
3822+
3823+
// Verify that our ped got actually removed from the ped pool
3824+
unsigned long const currentPedCount = g_pGame->GetPools()->GetPedCount();
3825+
assert(currentPedCount < previousPedCount);
38133826

38143827
// Remove the reference to its model
38153828
m_pLoadedModelInfo->RemoveRef();

0 commit comments

Comments
 (0)