Don't accept NaN geom sizes.
PiperOrigin-RevId: 542209911 Change-Id: I80f9728e8e624d19783370ba5072f39624c1bbe7
This commit is contained in:
committed by
Copybara-Service
parent
516c5a8bbe
commit
74747e2ae6
@@ -1717,6 +1717,11 @@ void mjCGeom::Compile(void) {
|
|||||||
size[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5]));
|
size[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (double s : size) {
|
||||||
|
if (std::isnan(s)) {
|
||||||
|
throw mjCError(this, "nan size in geom '%s' (id = %d)", name.c_str(), id);
|
||||||
|
}
|
||||||
|
}
|
||||||
// compute aabb
|
// compute aabb
|
||||||
ComputeAABB();
|
ComputeAABB();
|
||||||
|
|
||||||
|
|||||||
@@ -440,6 +440,27 @@ TEST_F(MjCGeomTest, IgnoreBadGeomOutsideInertiagrouprange) {
|
|||||||
mj_deleteModel(m);
|
mj_deleteModel(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------- test invalid size values --------------------------------------
|
||||||
|
|
||||||
|
TEST_F(MjCGeomTest, NanSize) {
|
||||||
|
// even if the caller ignores warnings, models shouldn't compile with NaN
|
||||||
|
// geom sizes
|
||||||
|
mju_user_warning = nullptr;
|
||||||
|
static constexpr char xml[] = R"(
|
||||||
|
<mujoco>
|
||||||
|
<worldbody>
|
||||||
|
<body>
|
||||||
|
<geom type="box" size="1 1 nan" mass="1" />
|
||||||
|
</body>
|
||||||
|
</worldbody>
|
||||||
|
</mujoco>
|
||||||
|
)";
|
||||||
|
std::array<char, 1000> error;
|
||||||
|
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
|
||||||
|
ASSERT_THAT(model, testing::IsNull());
|
||||||
|
ASSERT_THAT(error.data(), HasSubstr("nan"));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------- test height fields --------------------------------------------
|
// ------------- test height fields --------------------------------------------
|
||||||
|
|
||||||
using MjCHFieldTest = MujocoTest;
|
using MjCHFieldTest = MujocoTest;
|
||||||
|
|||||||
Reference in New Issue
Block a user