Add error checking in mjs_setFrame.

Also raise error if the frame is not found in the mjCBody copy constructor.

Fixes #2543.

PiperOrigin-RevId: 742624013
Change-Id: I4999b3165c97f8d079412214d027ca7a8dae8cb3
This commit is contained in:
Alessio Quaglino
2025-04-01 03:33:54 -07:00
committed by Copybara-Service
parent ebd30493c8
commit 86c970bc23
11 changed files with 125 additions and 25 deletions
+61
View File
@@ -1449,6 +1449,67 @@ TEST_F(XMLReaderTest, ParseReplicateRepeatedName) {
EXPECT_THAT(error.data(), HasSubstr("Element 'replicate'"));
}
TEST_F(XMLReaderTest, RepeatedPrefix) {
static constexpr char parent[] = R"(
<mujoco>
<asset>
<model name="1" file="child_1.xml" content_type="text/xml" />
<model name="2" file="child_2.xml" content_type="text/xml" />
</asset>
<worldbody>
<attach model="1" body="1" prefix="prefix-"/>
<replicate count="1">
<attach model="2" body="2" prefix="prefix-"/>
</replicate>
</worldbody>
</mujoco>
)";
static constexpr char child_1[] = R"(
<mujoco>
<asset>
<model name="2" file="child_2.xml" content_type="text/xml"/>
</asset>
<worldbody>
<body name="1">
<body name="2">
<attach model="2" body="2" prefix="prefix2"/>
</body>
</body>
</worldbody>
</mujoco>
)";
static constexpr char child_2[] = R"(
<mujoco>
<worldbody>
<body name="2"/>
</worldbody>
</mujoco>
)";
auto vfs = std::make_unique<mjVFS>();
mj_defaultVFS(vfs.get());
mj_addBufferVFS(vfs.get(), "child_1.xml", child_1, sizeof(child_1));
mj_addBufferVFS(vfs.get(), "child_2.xml", child_2, sizeof(child_2));
std::array<char, 1024> err;
mjSpec* c2 = mj_parseXMLString(child_2, 0, err.data(), err.size());
EXPECT_THAT(c2, NotNull()) << err.data();
mjSpec* c1 = mj_parseXMLString(child_1, vfs.get(), err.data(), err.size());
EXPECT_THAT(c1, NotNull()) << err.data();
mj_deleteSpec(c1);
mj_deleteSpec(c2);
mjSpec* spec = mj_parseXMLString(parent, vfs.get(), err.data(), err.size());
EXPECT_THAT(spec, IsNull());
EXPECT_THAT(err.data(), HasSubstr("mismatched parents"));
mj_deleteSpec(spec);
mj_deleteVFS(vfs.get());
}
TEST_F(XMLReaderTest, ParseReplicateExcludeTendon) {
static constexpr char xml[] = R"(
<mujoco>