Skip to content

Commit e00bd62

Browse files
better fix for CPhysHinge::Activate() crash, fix for saverestore crash in CPhysSlideConstraint::Activate() pointing to VelocitySampler::GetRelativeVelocity()
1 parent 7b2f53b commit e00bd62

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/game/server/physconstraint.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -940,16 +940,21 @@ void CPhysHinge::Activate( void )
940940
m_soundInfo.OnActivate(this);
941941
if (m_pConstraint)
942942
{
943-
if (m_soundInfo.m_iszTravelSoundFwd != NULL_STRING || m_soundInfo.m_iszTravelSoundBack != NULL_STRING || m_soundInfo.m_pTravelSound != nullptr)
943+
if (
944+
m_soundInfo.m_iszTravelSoundFwd != NULL_STRING ||
945+
m_soundInfo.m_iszTravelSoundBack != NULL_STRING ||
946+
m_soundInfo.m_pTravelSound != nullptr ||
947+
m_pConstraint->GetAttachedObject() != nullptr
948+
)
944949
{
945950
m_soundInfo.StartThinking(this,
946951
VelocitySampler::GetRelativeAngularVelocity(m_pConstraint->GetAttachedObject(), m_pConstraint->GetReferenceObject()) ,
947952
m_hinge.worldAxisDirection
948953
);
949-
}
950954

951-
SetThink(&CPhysHinge::SoundThink);
952-
SetNextThink( gpGlobals->curtime + m_soundInfo.getThinkRate() );
955+
SetThink(&CPhysHinge::SoundThink);
956+
SetNextThink( gpGlobals->curtime + m_soundInfo.getThinkRate() );
957+
}
953958
}
954959
}
955960

@@ -1277,13 +1282,24 @@ void CPhysSlideConstraint::Activate( void )
12771282
Vector axisDirection = m_axisEnd - GetAbsOrigin();
12781283
VectorNormalize( axisDirection );
12791284
UTIL_SnapDirectionToAxis( axisDirection );
1280-
m_soundInfo.StartThinking(this,
1281-
VelocitySampler::GetRelativeVelocity(m_pConstraint->GetAttachedObject(), m_pConstraint->GetReferenceObject()),
1282-
axisDirection
1283-
);
1285+
if ( m_pConstraint )
1286+
{
1287+
if (
1288+
m_soundInfo.m_iszTravelSoundFwd != NULL_STRING ||
1289+
m_soundInfo.m_iszTravelSoundBack != NULL_STRING ||
1290+
m_soundInfo.m_pTravelSound != nullptr ||
1291+
m_pConstraint->GetReferenceObject() != nullptr
1292+
)
1293+
{
1294+
m_soundInfo.StartThinking(this,
1295+
VelocitySampler::GetRelativeVelocity(m_pConstraint->GetAttachedObject(), m_pConstraint->GetReferenceObject()),
1296+
axisDirection
1297+
);
12841298

1285-
SetThink(&CPhysSlideConstraint::SoundThink);
1286-
SetNextThink(gpGlobals->curtime + m_soundInfo.getThinkRate());
1299+
SetThink(&CPhysSlideConstraint::SoundThink);
1300+
SetNextThink(gpGlobals->curtime + m_soundInfo.getThinkRate());
1301+
}
1302+
}
12871303
}
12881304

12891305
void CPhysSlideConstraint::Precache()

src/game/server/physconstraint_sounds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ class ConstraintSoundInfo
187187
Vector VelocitySampler::GetRelativeVelocity( IPhysicsObject *pObj, IPhysicsObject *pReferenceFrame )
188188
{
189189
Vector childVelocity, parentVelocity;
190+
191+
if (!pObj)
192+
return { 0,0,0 };
193+
190194
pObj->GetImplicitVelocity( &childVelocity, NULL );
191195
pReferenceFrame->GetImplicitVelocity(&parentVelocity, NULL);
192196

0 commit comments

Comments
 (0)