Skip to content

Commit 0532e91

Browse files
Quick fix for a out of range error that could occur (#236)
This error could occur when a template has a skeleton referencing joints that are not present in template
1 parent f784063 commit 0532e91

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

com.unity.perception/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Fixed a bug where uniform probabilities were not properly reset upon adding or r
7373

7474
Fixed keypoints being reported in wrong locations on the first frame an object is visible.
7575

76+
Fixed an out of range error if a keypoint template skeleton relies on a joint that is not available.
77+
7678
## [0.7.0-preview.2] - 2021-02-08
7779

7880
### Upgrade Notes

com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ string GetPose(Animator animator)
449449
return "unset";
450450
}
451451

452+
Keypoint GetKeypointForJoint(KeypointEntry entry, int joint)
453+
{
454+
if (joint < 0 || joint >= entry.keypoints.Length) return null;
455+
return entry.keypoints[joint];
456+
}
457+
452458
/// <inheritdoc/>
453459
protected override void OnVisualize()
454460
{
@@ -464,10 +470,10 @@ protected override void OnVisualize()
464470
{
465471
foreach (var bone in activeTemplate.skeleton)
466472
{
467-
var joint1 = entry.keypoints[bone.joint1];
468-
var joint2 = entry.keypoints[bone.joint2];
473+
var joint1 = GetKeypointForJoint(entry, bone.joint1);
474+
var joint2 = GetKeypointForJoint(entry, bone.joint2);
469475

470-
if (joint1.state == 2 && joint2.state == 2)
476+
if (joint1 != null && joint1.state == 2 && joint2 != null && joint2.state == 2)
471477
{
472478
VisualizationHelper.DrawLine(joint1.x, joint1.y, joint2.x, joint2.y, bone.color, 8, skeletonTexture);
473479
}

0 commit comments

Comments
 (0)