Skip to content

Commit

Permalink
Adds more joint debug asserts (#4490)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Oct 15, 2023
1 parent a9df909 commit 2ade6c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
25 changes: 24 additions & 1 deletion Robust.Shared/Physics/Systems/SharedJointSystem.Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -110,5 +109,29 @@ public void RefreshRelay(EntityUid uid, EntityUid? relay, JointComponent? compon
}

Dirty(uid, component);

#if DEBUG
if (component.Relay == null)
return;

if (TryComp(uid, out JointComponent? jointComp))
{
foreach (var joint in jointComp.Joints.Values)
{
DebugTools.AssertNotEqual(joint.BodyAUid, component.Relay);
DebugTools.AssertNotEqual(joint.BodyBUid, component.Relay);

}
}

if (TryComp(component.Relay, out JointComponent? relayJointComp))
{
foreach (var joint in relayJointComp.Joints.Values)
{
DebugTools.AssertNotEqual(joint.BodyAUid, uid);
DebugTools.AssertNotEqual(joint.BodyBUid, uid);
}
}
#endif
}
}
10 changes: 6 additions & 4 deletions Robust.Shared/Physics/Systems/SharedJointSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ private void InitJoint(Joint joint,
jointComponentA ??= EnsureComp<JointComponent>(aUid);
jointComponentB ??= EnsureComp<JointComponent>(bUid);
DebugTools.Assert(jointComponentA.Owner == aUid && jointComponentB.Owner == bUid);
DebugTools.AssertNotEqual(jointComponentA.Relay, bUid);
DebugTools.AssertNotEqual(jointComponentB.Relay, aUid);

var jointsA = jointComponentA.Joints;
var jointsB = jointComponentB.Joints;
Expand Down Expand Up @@ -190,10 +192,10 @@ private void InitJoint(Joint joint,

_physics.WakeBody(aUid, body: bodyA);
_physics.WakeBody(bUid, body: bodyB);
Dirty(bodyA);
Dirty(bodyB);
Dirty(jointComponentA);
Dirty(jointComponentB);
Dirty(aUid, bodyA);
Dirty(bUid, bodyB);
Dirty(aUid, jointComponentA);
Dirty(bUid, jointComponentB);

// Also flag these for checking juusssttt in case.
_dirtyJoints.Add(jointComponentA);
Expand Down
3 changes: 3 additions & 0 deletions Robust.Shared/Physics/Systems/SharedPhysicsSystem.Island.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,19 @@ private void Solve(EntityUid uid, PhysicsMapComponent component, float frameTime

var uidA = joint.BodyAUid;
var uidB = joint.BodyBUid;
DebugTools.AssertNotEqual(uidA, uidB);

if (jointQuery.TryGetComponent(uidA, out var jointCompA) &&
jointCompA.Relay != null)
{
DebugTools.AssertNotEqual(uidB, jointCompA.Relay.Value);
uidA = jointCompA.Relay.Value;
}

if (jointQuery.TryGetComponent(uidB, out var jointCompB) &&
jointCompB.Relay != null)
{
DebugTools.AssertNotEqual(uidA, jointCompB.Relay.Value);
uidB = jointCompB.Relay.Value;
}

Expand Down

0 comments on commit 2ade6c0

Please sign in to comment.