Skip to content

Conversation

@jslee02
Copy link
Member

@jslee02 jslee02 commented Jan 17, 2026

Summary

  • Add NaN/Inf validation to BodyNode::addExtForce, setExtForce, addExtTorque, setExtTorque
  • Add NaN/Inf validation to PointMass::addExtForce
  • Invalid values are logged as warnings and ignored to prevent simulation crashes

Related Issue

Addresses gz-physics#844 - Crash in BodyNode::updateBiasForce when Gazebo Hydrodynamics plugin passes NaN parameters (e.g., <xDotU>NaN</xDotU>).

Changes

File Change
dart/dynamics/BodyNode.cpp Validate force/torque vectors before applying
dart/dynamics/PointMass.cpp Validate force vector before applying
tests/unit/dynamics/test_BodyNodeExternalForce.cpp 9 unit tests for NaN/Inf handling
tests/unit/dynamics/CMakeLists.txt Updated test target

Testing

All 9 new unit tests pass locally:

  • AddExtForceWithNaN
  • AddExtForceWithInf
  • AddExtForceWithNaNOffset
  • SetExtForceWithNaN
  • AddExtTorqueWithNaN
  • AddExtTorqueWithInf
  • SetExtTorqueWithNaN
  • ValidForceApplication
  • GzPhysics844Scenario

@jslee02 jslee02 added this to the DART 7.0 milestone Jan 17, 2026
@jslee02 jslee02 force-pushed the fix/nan-external-force-validation branch from 0b33efd to 9763d72 Compare January 17, 2026 19:33
@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 71.11111% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.51%. Comparing base (a15166f) to head (36a6f7e).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
dart/dynamics/PointMass.cpp 0.00% 7 Missing ⚠️
dart/dynamics/BodyNode.cpp 84.21% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2444      +/-   ##
==========================================
+ Coverage   66.49%   66.51%   +0.02%     
==========================================
  Files         407      407              
  Lines       37254    37283      +29     
  Branches     4901     4910       +9     
==========================================
+ Hits        24772    24800      +28     
- Misses      12482    12483       +1     
Flag Coverage Δ
unittests 66.51% <71.11%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
dart/dynamics/BodyNode.hpp 0.00% <ø> (ø)
dart/dynamics/PointMass.hpp 100.00% <ø> (ø)
dart/dynamics/BodyNode.cpp 83.98% <84.21%> (+0.07%) ⬆️
dart/dynamics/PointMass.cpp 48.14% <0.00%> (-0.32%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Adds validation to BodyNode and PointMass external force setters to
check for NaN and Inf values. When invalid values are detected, a
warning is logged and the operation is skipped, preventing the
simulation from crashing due to NaN propagation.

This addresses gz-physics#844 where NaN hydrodynamics parameters cause
assertion failures in BodyNode::updateBiasForce.

Modified files:
- dart/dynamics/BodyNode.cpp: Add validation to addExtForce,
  setExtForce, addExtTorque, setExtTorque
- dart/dynamics/PointMass.cpp: Add validation to addExtForce
- tests/unit/dynamics/test_BodyNodeExternalForce.cpp: New test file
- tests/unit/CMakeLists.txt: Register new test
@jslee02 jslee02 force-pushed the fix/nan-external-force-validation branch from d6e88ba to 36a6f7e Compare January 18, 2026 06:39
@jslee02
Copy link
Member Author

jslee02 commented Jan 18, 2026

@codex review

This PR has been rebased on main to incorporate the new error handling infrastructure from #2445. The validation approach using DART_WARN with early return is appropriate for this use case (handling NaN/Inf external forces from hydrodynamics parameters in gz-physics).

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jslee02 jslee02 merged commit 3f10fa4 into main Jan 18, 2026
46 checks passed
@jslee02 jslee02 deleted the fix/nan-external-force-validation branch January 18, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants