Improve error text when a mesh face references an invalid vertex.

PiperOrigin-RevId: 618715730
Change-Id: I28fae1e1570d359db4be98e9c5b7713169eaf34f
This commit is contained in:
Matthew Bennice
2024-03-24 20:58:08 -07:00
committed by Copybara-Service
parent bb42ff1657
commit 7875e93fea
2 changed files with 27 additions and 1 deletions
+2 -1
View File
@@ -549,7 +549,8 @@ void mjCMesh::Compile(const mjVFS* vfs) {
// check vertices exist
for (int i=0; i<userface_.size(); i++) {
if (userface_[i] >= nvert_ || userface_[i] < 0) {
throw mjCError(this, "index in face does not exist in vertex array");
throw mjCError(this, "in face %d, vertex index %d does not exist",
nullptr, i / 3, userface_[i]);
}
}
+25
View File
@@ -945,6 +945,31 @@ TEST_F(MjCMeshTest, NaNConvexHullDisallowed) {
mj_deleteModel(model);
}
TEST_F(MjCMeshTest, InvalidIndexInFace) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
<mesh name="example_mesh"
vertex="0 0 0 1 0 0 0 1 0 0 0 1"
normal="1 0 0 0 1 0 0 0 1 0.707 0 0.707"
face="0 2 6 0 3 2" />
</asset>
<worldbody>
<geom type="mesh" mesh="example_mesh"/>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, IsNull());
EXPECT_THAT(
error.data(),
HasSubstr(
"in face 0, vertex index 6 does not exist"));
mj_deleteModel(model);
}
} // namespace
} // namespace mujoco