Skip to content

Commit 0e8ab99

Browse files
committed
Crash fix for calling a CAutomobile function on a CTrain
1 parent adfbd69 commit 0e8ab99

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

Client/mods/deathmatch/logic/CClientVehicle.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ void CClientVehicle::PlaceProperlyOnGround()
17581758
{
17591759
m_pVehicle->PlaceBikeOnRoadProperly();
17601760
}
1761-
else if (m_eVehicleType != CLIENTVEHICLE_BOAT)
1761+
else if (m_eVehicleType != CLIENTVEHICLE_BOAT && m_eVehicleType != CLIENTVEHICLE_TRAIN)
17621762
{
17631763
m_pVehicle->PlaceAutomobileOnRoadProperly();
17641764
}
@@ -2744,23 +2744,50 @@ void CClientVehicle::Create()
27442744
// Reattach a towed vehicle?
27452745
if (m_pTowedVehicle)
27462746
{
2747-
// Make sure that the trailer is streamed in
2748-
if (!m_pTowedVehicle->GetGameVehicle())
2747+
if (GetVehicleType() == CLIENTVEHICLE_TRAIN)
27492748
{
2750-
m_pTowedVehicle->StreamIn(true);
2751-
}
2749+
// A train is never towing other vehicles, other trains are linked by other means
2750+
m_pTowedVehicle->m_pTowedByVehicle = nullptr;
27522751

2753-
// Attach him
2754-
if (m_pTowedVehicle->GetGameVehicle())
2752+
// Stream-in the old unlinked trailer
2753+
if (!m_pTowedVehicle->GetGameVehicle())
2754+
{
2755+
m_pTowedVehicle->StreamIn(true);
2756+
}
2757+
2758+
m_pTowedVehicle = nullptr;
2759+
}
2760+
else
27552761
{
2756-
InternalSetTowLink(m_pTowedVehicle);
2762+
// Make sure that the trailer is streamed in
2763+
if (!m_pTowedVehicle->GetGameVehicle())
2764+
{
2765+
m_pTowedVehicle->StreamIn(true);
2766+
}
2767+
2768+
if (m_pTowedVehicle->GetGameVehicle())
2769+
{
2770+
InternalSetTowLink(m_pTowedVehicle);
2771+
}
27572772
}
27582773
}
27592774

27602775
// Reattach if we're being towed
2761-
if (m_pTowedByVehicle && m_pTowedByVehicle->GetGameVehicle())
2776+
if (m_pTowedByVehicle)
27622777
{
2763-
m_pTowedByVehicle->InternalSetTowLink(this);
2778+
if (GetVehicleType() == CLIENTVEHICLE_TRAIN)
2779+
{
2780+
// A train is never towed by other vehicles, it's linked by other means
2781+
m_pTowedByVehicle->m_pTowedVehicle = nullptr;
2782+
m_pTowedByVehicle = nullptr;
2783+
}
2784+
else
2785+
{
2786+
if (m_pTowedByVehicle->GetGameVehicle())
2787+
{
2788+
m_pTowedByVehicle->InternalSetTowLink(this);
2789+
}
2790+
}
27642791
}
27652792

27662793
// Reattach to an entity + any entities attached to this

0 commit comments

Comments
 (0)