Skip to content

Conversation

@jslee02
Copy link
Member

@jslee02 jslee02 commented Jan 16, 2026

Summary

  • Add validation for NaN/Inf/negative friction, restitution, and slip compliance values in ContactSurface and SoftContactConstraint
  • Invalid values now log a warning and fall back to defaults, preventing assertion failures in the LCP solver

Problem

When malformed SDF files contain invalid friction values (e.g., <mu>NaN</mu>), these propagate through DART's constraint system and cause an assertion failure in dSolveLCP:

lo[k] <= 0 && hi[k] >= 0

This crashes simulations in gz-physics and any other downstream consumers.

Solution

Validate contact surface parameters at extraction time in:

  • DefaultContactSurfaceHandler::computeFrictionCoefficient()
  • DefaultContactSurfaceHandler::computePrimaryFrictionCoefficient()
  • DefaultContactSurfaceHandler::computeSecondaryFrictionCoefficient()
  • DefaultContactSurfaceHandler::computePrimarySlipCompliance()
  • DefaultContactSurfaceHandler::computeSecondarySlipCompliance()
  • DefaultContactSurfaceHandler::computeRestitutionCoefficient()
  • SoftContactConstraint::computeFrictionCoefficient()
  • SoftContactConstraint::computeRestitutionCoefficient()

Invalid values are rejected with a warning and replaced with safe defaults.

Testing

  • Added 21 new unit tests covering NaN, Inf, negative, and valid value cases
  • All 137 existing tests pass
  • LCP solver benchmarks show no performance regression

Related Issues

Related to gazebosim/gz-physics#841

Checklist

  • Code compiles without errors
  • All tests pass
  • Added new tests for the fix
  • Updated CHANGELOG.md

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 58.82353% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.49%. Comparing base (a15166f) to head (12529fc).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
dart/constraint/SoftContactConstraint.cpp 0.00% 10 Missing ⚠️
dart/constraint/ContactSurface.cpp 83.33% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2434   +/-   ##
=======================================
  Coverage   66.49%   66.49%           
=======================================
  Files         407      407           
  Lines       37254    37278   +24     
  Branches     4901     4906    +5     
=======================================
+ Hits        24772    24788   +16     
- Misses      12482    12490    +8     
Flag Coverage Δ
unittests 66.49% <58.82%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
dart/constraint/ContactSurface.cpp 86.13% <83.33%> (+1.00%) ⬆️
dart/constraint/SoftContactConstraint.cpp 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

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

@jslee02 jslee02 added this to the DART 7.0 milestone Jan 16, 2026
@jslee02 jslee02 changed the title fix: validate contact surface parameters to prevent LCP solver crashes fix: validate contact surface parameters to prevent LCP solver crashes (DART 7) Jan 16, 2026
@jslee02 jslee02 force-pushed the fix/nan-friction-validation branch from ebdc799 to 7028b70 Compare January 17, 2026 08:58
@jslee02
Copy link
Member Author

jslee02 commented Jan 17, 2026

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ 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".

Add validation for NaN/Inf/negative friction, restitution, and slip
compliance values in ContactSurface and SoftContactConstraint.
Invalid values now log a warning and fall back to defaults.

This prevents assertion failures in the LCP solver when malformed SDF
files (e.g., <mu>NaN</mu>) propagate invalid values through the
constraint system.

Fixes gazebosim/gz-physics#841
Fully qualify constraint::DART_DEFAULT_FRICTION_COEFF and
constraint::DART_DEFAULT_RESTITUTION_COEFF to avoid ambiguity with
dynamics namespace constants.

Also refactored validation to use DART_WARN_IF for consistency.
@jslee02 jslee02 force-pushed the fix/nan-friction-validation branch from 1aaadf5 to 12529fc Compare January 18, 2026 06:35
@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 fallback to default values is appropriate for this use case (expected failures from malformed SDF data).

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ 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 74a67fc into main Jan 18, 2026
46 checks passed
@jslee02 jslee02 deleted the fix/nan-friction-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