Fix segfault on a mesh with convex inertia that no geom references
needhull_ was only set while iterating geoms, so a mesh whose inertia is computed from its convex hull never got one unless some geom pointed at it. mjCMesh::ComputeVolume and ComputeInertia then read graph_[1] and GraphFaces() off a null pointer and the compiler crashed. Whether a mesh needs its hull for inertia is a property of the mesh, not of any geom, so move that condition out of the geom loop and apply it to every mesh. Fixes #3431
This commit is contained in:
@@ -975,6 +975,22 @@ TEST_F(MjCMeshTest, ExactConvexInertia) {
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(MjCMeshTest, UnreferencedConvexInertiaMesh) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
<asset>
|
||||
<mesh name="orphan" inertia="convex"
|
||||
vertex="0 0 1 1 0 0 0 1 0 -1 0 0 0 -1 0"
|
||||
face="0 1 2 0 2 3 0 3 4 0 4 1 1 4 3 1 3 2"/>
|
||||
</asset>
|
||||
<worldbody/>
|
||||
</mujoco>
|
||||
)";
|
||||
std::array<char, 1024> error;
|
||||
MjModelPtr model = LoadModelFromString(xml, error.data(), error.size());
|
||||
EXPECT_THAT(model.get(), NotNull()) << error.data();
|
||||
}
|
||||
|
||||
TEST_F(MjCMeshTest, ExactShellInertia) {
|
||||
const std::string xml_path = GetTestDataFilePath(kShellInertiaPath);
|
||||
std::array<char, 1024> error;
|
||||
|
||||
Reference in New Issue
Block a user