Skip to content
Permalink
Browse files

Add null pointer checks for code using CClientGame::GetLocalPlayer()

  • Loading branch information...
botder committed Sep 8, 2019
1 parent 5727bb3 commit ff6715d7354d54b821672aa83fecf82457299575
@@ -835,5 +835,15 @@ void CClientObject::SetVisibleInAllDimensions(bool bVisible, unsigned short usNe
m_bVisibleInAllDimensions = bVisible;

// Stream-in/out the object as needed
this->SetDimension(bVisible ? g_pClientGame->GetLocalPlayer()->GetDimension() : usNewDimension);
if (bVisible)
{
if (g_pClientGame->GetLocalPlayer())
{
SetDimension(g_pClientGame->GetLocalPlayer()->GetDimension());
}
}
else
{
SetDimension(usNewDimension);
}
}
@@ -299,7 +299,7 @@ CClientPed::~CClientPed()
CClientVehicle* pVehicle = GetOccupiedVehicle();
if (m_pPlayerPed && pVehicle && GetOccupiedVehicleSeat() == 0)
{
if (g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle)
if (g_pClientGame->GetLocalPlayer() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle)
{
CVehicle* pGameVehicle = pVehicle->GetGameVehicle();
if (pGameVehicle)
@@ -1436,7 +1436,7 @@ void CClientPed::WarpIntoVehicle(CClientVehicle* pVehicle, unsigned int uiSeat)
// Warp him in
InternalWarpIntoVehicle(pGameVehicle);

if (m_bIsLocalPlayer || g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle)
if (m_bIsLocalPlayer || (g_pClientGame->GetLocalPlayer() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle))
{
// Tell vehicle audio we have driver
pGameVehicle->GetVehicleAudioEntity()->JustGotInVehicleAsDriver();
@@ -1568,7 +1568,7 @@ CClientVehicle* CClientPed::RemoveFromVehicle(bool bSkipWarpIfGettingOut)
if (pVehicle != m_pOccupyingVehicle && pVehicle->GetOccupant())
{
// Local player left vehicle or got abandoned by remote driver
if ((m_bIsLocalPlayer || (m_uiOccupiedVehicleSeat == 0 && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle)))
if ((m_bIsLocalPlayer || (m_uiOccupiedVehicleSeat == 0 && (g_pClientGame->GetLocalPlayer() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == pVehicle))))
{
// Tell vehicle audio the driver left
pGameVehicle->GetVehicleAudioEntity()->JustGotOutOfVehicleAsDriver();
@@ -297,7 +297,7 @@ void CClientVehicle::GetPosition(CVector& vecPosition) const
void CClientVehicle::SetPosition(const CVector& vecPosition, bool bResetInterpolation, bool bAllowGroundLoadFreeze)
{
// Is the local player in the vehicle
if (g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == this)
if (g_pClientGame->GetLocalPlayer() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == this)
{
// If move is big enough, do ground checks
float DistanceMoved = (m_Matrix.vPos - vecPosition).Length();
@@ -3760,7 +3760,7 @@ void CClientVehicle::UpdateTargetPosition()
}

#ifdef MTA_DEBUG
if (g_pClientGame->IsShowingInterpolation() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == this)
if (g_pClientGame->IsShowingInterpolation() && g_pClientGame->GetLocalPlayer() && g_pClientGame->GetLocalPlayer()->GetOccupiedVehicle() == this)
{
// DEBUG
SString strBuffer(
@@ -194,7 +194,8 @@ void CFoo::Test(const char* szString)

else if (stricmp(szString, "choke") == 0)
{
g_pClientGame->GetLocalPlayer()->SetChoking(true);
if (g_pClientGame->GetLocalPlayer())
g_pClientGame->GetLocalPlayer()->SetChoking(true);
}

//

0 comments on commit ff6715d

Please sign in to comment.
You can’t perform that action at this time.