Throw error if qhull is called with NaNs.

PiperOrigin-RevId: 601745538
Change-Id: I590673ca7975e4abc171f98704a6c8f8d08f8327
This commit is contained in:
Alessio Quaglino
2024-01-26 06:12:33 -08:00
committed by Copybara-Service
parent 076db5d366
commit fb8f77df74
2 changed files with 26 additions and 0 deletions
+4
View File
@@ -1506,6 +1506,10 @@ void mjCMesh::MakeGraph(void) {
throw mjCError(this, "could not allocate data for qhull");
}
for (int i=0; i<3*nvert_; i++) {
if (!std::isfinite(vert_[i])) {
mju_free(data);
throw mjCError(this, "vertex coordinate %d is not finite", NULL, i);
}
data[i] = (double)vert_[i];
}
+22
View File
@@ -923,6 +923,28 @@ TEST_F(MjCMeshTest, MissingTexCoord) {
EXPECT_THAT(error.data(), HasSubstr("texcoord must be 2*nv"));
}
// ----------------------------- qhull ----------------------------------------
TEST_F(MjCMeshTest, NaNConvexHullDisallowed) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
<mesh name="mesh"vertex="nan 0 0 0 1 0 0 1 0 0 0 1"/>
</asset>
</mujoco>
)";
static char warning[1024];
warning[0] = '\0';
mju_user_warning = [](const char* msg) {
util::strcpy_arr(warning, msg);
};
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, testing::IsNull());
EXPECT_THAT(error.data(), HasSubstr("vertex coordinate 0 is not finite"));
mj_deleteModel(model);
}
} // namespace
} // namespace mujoco