Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GzOdeCollisionDetector: Use static mutex in create method to avoid problems with non-thread-safe ODE functions #675

Open
wants to merge 1 commit into
base: gz-physics7
Choose a base branch
from

Conversation

traversaro
Copy link
Contributor

@traversaro traversaro commented Aug 21, 2024

🦟 Bug fix

Summary

This is done to avoid that non-thread-safe ODE functions are called at the same time, causing errors such as

ODE INTERNAL ERROR 1: assertion "!colliders_initialized" failed in dInitColliders() [collision_kernel.cpp:168]

Why this happens? As the GzOdeCollisionDetector constructor calls the DART's OdeCollisionDetector constructor, that instead calls the non-thread-safe dInitODE2(0) ode function. If dInitODE2(0) is called at different times, everything seems to be working fine, so we enforce this by adding a static std::mutex in the GzOdeCollisionDetector::create.

This fixes part of gazebosim/gz-sim#18 . Note that this does not solve all the ODE-related multi-threading problems, but at least allows to set a different collision manager without having errors such as:

ODE INTERNAL ERROR 1: assertion "!colliders_initialized" failed in dInitColliders() [collision_kernel.cpp:168]

That happens as GzOdeCollisionDetector is allocated before the requested collision detector is set by WorldFeatures::SetWorldCollisionDetector, so it is not possible to avoid to construct ``GzOdeCollisionDetector` by specifying a custom collision detector in the SDF, unless we want to change the default collision detector, that is something we want to avoid (at least at the moment) as discussed in gazebosim/gz-sim#18 .

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

This is done to avoid that non-thread-safe ODE functions are called at the same time, causing errors such as 
> ODE INTERNAL ERROR 1: assertion "!colliders_initialized" failed in dInitColliders() [collision_kernel.cpp:168]

Signed-off-by: Silvio Traversaro <[email protected]>
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Aug 21, 2024
@traversaro
Copy link
Contributor Author

I consider adding tests for this, but the race condition that results in errors such as:

ODE INTERNAL ERROR 1: assertion "!colliders_initialized" failed in dInitColliders() [collision_kernel.cpp:168]

is extremely complex to reproduce (I was able to do so just with apt dependencies and in Debug mode) so I am not sure it is useful to try to reproduce this in a test.

@traversaro traversaro changed the title GzOdeCollisionDetector: Use static mutex in create GzOdeCollisionDetector: Use static mutex in create method to avoid problems with non-thread-safe ODE functions Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Status: Inbox
Development

Successfully merging this pull request may close these issues.

1 participant