diff --git a/dartsim/src/plugin.cc b/dartsim/src/plugin.cc index ed9029c15..28985ee1f 100644 --- a/dartsim/src/plugin.cc +++ b/dartsim/src/plugin.cc @@ -57,6 +57,31 @@ class Plugin : public virtual ShapeFeatures, public virtual SimulationFeatures { }; +namespace { + +// This is done as a partial fix for +// https://github.com/gazebosim/gz-physics/issues/442. The issue seems like the +// destructors for the concrete collision detectors get unloaded and deleted +// from memory before the destructors run. When it's time to actually call the +// destructors, a segfault is generated. +// +// It's not clear why the destructors are deleted prematurely. It might be a +// compiler optimization in new compiler versions. +// +// The solution here is to call the `unregisterAllCreators` function from the +// plugins translation unit in the hopes that it will force the compiler to keep +// the destructors. +struct UnregisterCollisionDetectors +{ + ~UnregisterCollisionDetectors() + { + dart::collision::CollisionDetector::getFactory()->unregisterAllCreators(); + } +}; + +UnregisterCollisionDetectors unregisterAtUnload; +} + IGN_PHYSICS_ADD_PLUGIN(Plugin, FeaturePolicy3d, DartsimFeatures) }