Skip to content

Infinite loop in SkeletonAnimation::PoseAtX when X-axis displacement is zero #741

@XINJIANGMO

Description

@XINJIANGMO

Environment

  • OS Version: Ubuntu 24.04
  • Source or binary build?
    source , gz-common7

Description

  • Expected behavior: The function should detect that the animation has no forward (X) displacement and handle it gracefully rather than looping forever.
  • Actual behavior: looping forever

Steps to reproduce

  1. add a test in SkeletonAnimation_TEST.cc
/////////////////////////////////////////////////
TEST_F(SkeletonAnimation, CheckPoseAtXLooping)
{
  common::SkeletonAnimation skelAnim("testAnimation");
  skelAnim.AddKeyFrame("node1", 1.0, math::Matrix4d::Identity);

  auto pose = skelAnim.PoseAtX(2.0, "node1", true);
  ASSERT_EQ(pose["node1"], math::Matrix4d::Identity);
}

Propose Fix

Fix in SkeletonAnimation.cc
function PoseAtX

if (lastX > 1e-6) {
    while (x > lastX)
        x -= lastX;
} else {
    x = 0; 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Inbox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions