Fix segfault in Bullet Featherstone plugin when loading ball joint#868
Conversation
Signed-off-by: momo <2438833481@qq.com>
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the Bullet Featherstone SDF model construction path when encountering joints without an axis definition (notably ball joints), improving robustness while loading SDF models.
Changes:
- Added a null check around
joint->Axis()before reading axis-dependent limits / damping / effort parameters. - Prevented axis-derived joint metadata from being populated when the axis is absent.
Comments suppressed due to low confidence (1)
bullet-featherstone/src/SDFFeatures.cc:862
- The new null check guards the property assignments, but
joint->Axis()is still dereferenced unconditionally when creatingbtMultiBodyJointLimitConstraint. IfAxis()can be nullptr for any non-ball joint (e.g., malformed SDF), this will still segfault. Consider cachingaxis = joint->Axis()once and only creating the limit constraint whenaxisis non-null (otherwise skip and emit an error/warning).
if (::sdf::JointType::BALL != joint->Type())
{
jointInfo->jointLimits =
std::make_shared<btMultiBodyJointLimitConstraint>(
model->body.get(), i,
static_cast<btScalar>(joint->Axis()->Lower()),
static_cast<btScalar>(joint->Axis()->Upper()));
world->world->addMultiBodyConstraint(jointInfo->jointLimits.get());
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (joint->Axis()) | ||
| { | ||
| model->body->getLink(i).m_jointLowerLimit = | ||
| static_cast<btScalar>(joint->Axis()->Lower()); | ||
| model->body->getLink(i).m_jointUpperLimit = | ||
| static_cast<btScalar>(joint->Axis()->Upper()); | ||
| model->body->getLink(i).m_jointFriction = | ||
| static_cast<btScalar>(joint->Axis()->Friction()); | ||
| model->body->getLink(i).m_jointMaxVelocity = | ||
| static_cast<btScalar>(joint->Axis()->MaxVelocity()); | ||
| model->body->getLink(i).m_jointMaxForce = | ||
| static_cast<btScalar>(joint->Axis()->Effort()); | ||
|
|
||
| jointInfo->minEffort = -joint->Axis()->Effort(); | ||
| jointInfo->maxEffort = joint->Axis()->Effort(); | ||
| jointInfo->minVelocity = -joint->Axis()->MaxVelocity(); | ||
| jointInfo->maxVelocity = joint->Axis()->MaxVelocity(); | ||
| jointInfo->axisLower = joint->Axis()->Lower(); | ||
| jointInfo->axisUpper = joint->Axis()->Upper(); | ||
| jointInfo->damping = joint->Axis()->Damping(); | ||
| jointInfo->springStiffness = joint->Axis()->SpringStiffness(); | ||
| jointInfo->springReference = joint->Axis()->SpringReference(); |
There was a problem hiding this comment.
Within the if (joint->Axis()) block, joint->Axis() is called repeatedly. Caching the pointer/reference once (e.g., const auto *axis = joint->Axis();) will make the code clearer and avoids repeated virtual calls / pointer chasing.
| @@ -828,26 +828,29 @@ Identity SDFFeatures::ConstructSdfModelImpl( | |||
| // bullet-featherstone and so setting them does not have any effect. | |||
| // The lower and uppper limit is supported via the | |||
There was a problem hiding this comment.
Typo in comment: "uppper" should be "upper".
| // The lower and uppper limit is supported via the | |
| // The lower and upper limit is supported via the |
| if (joint->Axis()) | ||
| { | ||
| model->body->getLink(i).m_jointLowerLimit = |
There was a problem hiding this comment.
This change fixes a crash during SDF model construction for ball joints with no axis; please add a regression test that loads an SDF/world containing a ball joint without an <axis> using the bullet-featherstone engine and asserts ConstructWorld (or ConstructModel) succeeds without crashing.
|
@Mergifyio backport gz-physics9 gz-physics8 gz-physics7 |
✅ Backports have been createdDetails
|
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
…azebosim#868) Signed-off-by: momo <2438833481@qq.com> (cherry picked from commit 2f8e332)
🦟 Bug fix
Fixes #864
Summary
Fixed a segmentation fault in the
Bullet Featherstoneplugin triggered by SDF models containing ball joints.Added a null pointer check for
joint->Axis()to prevent invalid access when loading joints that lack an axis definition.Checklist
codecheckpassed (See contributing)