Skip to content

Commit

Permalink
Fix bullet related segfaults on macOS (#504)
Browse files Browse the repository at this point in the history
This fixes two tests with segfaults on macOS

* COMMON_TEST_simulation_features_bullet-featherstone: The failure appears to be due to the destruction order of the triangleMeshes and meshesGImpact containers. Per [this] (Should btBroadphaseInterface destructor remove itself from btCollisionObject broadphase proxies?  bulletphysics/bullet3#567 (comment)) comment, memory in bullet is sensitive to order of destruction. meshesGImpact objects contain pointers to items contained bytriangleMeshes, so the solution is to ensure meshesGImpact is destructed before triangleMeshes.
* INTEGRATION_DoublePendulum: This is a DART test, but the segfault seems to be related to Bullet. I found that even after removing all the code in DARTDoublePendulum.cc, the segfault still occurs as long as it's linked with libdart-collision-bullet. Since the test doesn't need the bullet collision detector, I've opted to just remove the library from the DART_LIBRARIES variable. I still don't know the root cause though, so this might affect the actual dartsim-plugin library.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
azeey authored Apr 7, 2023
1 parent 12baaf7 commit 35d02fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bullet-featherstone/src/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ class Base : public Implements3d<FeatureList<Feature>>
public: std::unordered_map<std::size_t, CollisionInfoPtr> collisions;
public: std::unordered_map<std::size_t, JointInfoPtr> joints;

public: std::vector<std::unique_ptr<btGImpactMeshShape>> meshesGImpact;
// Note, the order of triangleMeshes and meshesGImpact is important. Reversing
// the order causes segfaults on macOS during destruction.
public: std::vector<std::unique_ptr<btTriangleMesh>> triangleMeshes;
public: std::vector<std::unique_ptr<btGImpactMeshShape>> meshesGImpact;
};

} // namespace bullet_featherstone
Expand Down
7 changes: 6 additions & 1 deletion test/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ foreach(plugin IN LISTS plugins)
endforeach()

if (DART_FOUND)
target_link_libraries(MockDoublePendulum PUBLIC ${DART_LIBRARIES})
# Linking against libdart-collision-bullet causes a segfault on macOS for
# some reason. We'll remove it since MockDoublePendulum doesn't use bullet
# for collision checking.
set(DART_LIBRARIES_NO_BULLET ${DART_LIBRARIES})
list(REMOVE_ITEM DART_LIBRARIES_NO_BULLET dart-collision-bullet)
target_link_libraries(MockDoublePendulum PUBLIC ${DART_LIBRARIES_NO_BULLET})
target_compile_definitions(MockDoublePendulum PRIVATE
"GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\"")
if (MSVC)
Expand Down

0 comments on commit 35d02fe

Please sign in to comment.