Skip to content

Commit fbdcf2f

Browse files
authored
Race condition patch for constraints (#1535)
2 parents 0f06ac0 + 75fa1aa commit fbdcf2f

File tree

1 file changed

+7
-7
lines changed
  • server/core/src/main/java/dev/slimevr/tracking/processor

1 file changed

+7
-7
lines changed

server/core/src/main/java/dev/slimevr/tracking/processor/Constraint.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ class Constraint(
5252
if (constraintType == ConstraintType.COMPLETE) return thisBone.getGlobalRotation()
5353

5454
// If there is no parent and this is not a complete constraint accept the rotation as is.
55-
if (thisBone.parent == null) return rotation
55+
// TODO: This was changed due to a race condition with the RPC thread, see
56+
// https://github.com/SlimeVR/SlimeVR-Server/issues/1534 for more information.
57+
val parent = thisBone.parent ?: return rotation
5658

57-
val localRotation = getLocalRotation(rotation, thisBone)
59+
val localRotation = getLocalRotation(rotation, thisBone, parent)
5860
val constrainedRotation = constraintFunction(localRotation, swingRad, twistRad, allowedDeviationRad)
59-
return getWorldRotationFromLocal(constrainedRotation, thisBone)
61+
return getWorldRotationFromLocal(constrainedRotation, thisBone, parent)
6062
}
6163

6264
/**
@@ -90,14 +92,12 @@ class Constraint(
9092
ConstraintType.LOOSE_HINGE -> looseHingeConstraint
9193
}
9294

93-
private fun getLocalRotation(rotation: Quaternion, thisBone: Bone): Quaternion {
94-
val parent = thisBone.parent!!
95+
private fun getLocalRotation(rotation: Quaternion, thisBone: Bone, parent: Bone): Quaternion {
9596
val localRotationOffset = parent.rotationOffset.inv() * thisBone.rotationOffset
9697
return (parent.getGlobalRotation() * localRotationOffset).inv() * rotation
9798
}
9899

99-
private fun getWorldRotationFromLocal(rotation: Quaternion, thisBone: Bone): Quaternion {
100-
val parent = thisBone.parent!!
100+
private fun getWorldRotationFromLocal(rotation: Quaternion, thisBone: Bone, parent: Bone): Quaternion {
101101
val localRotationOffset = parent.rotationOffset.inv() * thisBone.rotationOffset
102102
return (parent.getGlobalRotation() * localRotationOffset * rotation).unit()
103103
}

0 commit comments

Comments
 (0)