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:
VihaanAgarwal
2026-07-26 16:04:15 -07:00
parent 559c2af751
commit 95f05402f1
2 changed files with 25 additions and 2 deletions
+9 -2
View File
@@ -5279,12 +5279,19 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
if (geoms_[i]->mesh &&
(geoms_[i]->spec.type == mjGEOM_MESH ||
geoms_[i]->spec.type == mjGEOM_SDF) &&
(geoms_[i]->spec.contype || geoms_[i]->spec.conaffinity || is_in_pair ||
geoms_[i]->mesh->spec.inertia == mjMESH_INERTIA_CONVEX)) {
(geoms_[i]->spec.contype || geoms_[i]->spec.conaffinity || is_in_pair)) {
geoms_[i]->mesh->SetNeedHull(true);
}
}
// convex inertia is computed from the hull, so it is needed whether or not
// any geom references the mesh
for (mjCMesh* mesh : meshes_) {
if (mesh->spec.inertia == mjMESH_INERTIA_CONVEX) {
mesh->SetNeedHull(true);
}
}
// automatically set nuser fields
SetNuser();