@@ -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