fixed joint crash when no lead entity is selected (#2867)

Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com>
This commit is contained in:
amzn-sean
2021-08-16 15:46:46 +01:00
committed by GitHub
parent 5925bd22f6
commit e630e3324d
5 changed files with 121 additions and 15 deletions
+17 -2
View File
@@ -46,11 +46,26 @@ namespace PhysX
JointComponent::LeadFollowerInfo leadFollowerInfo;
ObtainLeadFollowerInfo(leadFollowerInfo);
if (!leadFollowerInfo.m_followerActor)
if (leadFollowerInfo.m_followerActor == nullptr ||
leadFollowerInfo.m_followerBody == nullptr)
{
return;
}
// if there is no lead body, this will be a constraint of the follower's global position, so use invalid body handle.
AzPhysics::SimulatedBodyHandle parentHandle = AzPhysics::InvalidSimulatedBodyHandle;
if (leadFollowerInfo.m_leadBody != nullptr)
{
parentHandle = leadFollowerInfo.m_leadBody->m_bodyHandle;
}
else
{
AZ_TracePrintf(
"PhysX", "Entity [%s] Ball Joint component missing lead entity. This joint will be a global constraint on the follower's global position.",
GetEntity()->GetName().c_str());
}
BallJointConfiguration configuration;
configuration.m_parentLocalPosition = leadFollowerInfo.m_leadLocal.GetTranslation();
configuration.m_parentLocalRotation = leadFollowerInfo.m_leadLocal.GetRotation();
@@ -65,7 +80,7 @@ namespace PhysX
m_jointHandle = sceneInterface->AddJoint(
leadFollowerInfo.m_followerBody->m_sceneOwner,
&configuration,
leadFollowerInfo.m_leadBody->m_bodyHandle,
parentHandle,
leadFollowerInfo.m_followerBody->m_bodyHandle);
m_jointSceneOwner = leadFollowerInfo.m_followerBody->m_sceneOwner;
}