Check that there are no pending keyframes while writing a spec.

This can happen when a body is detached without compiling or recompiling.

Also added error catching when trying to delete a body instead of detaching it.

Fixes #2327

PiperOrigin-RevId: 712526730
Change-Id: I4b48df83120fca12d475c85b3a54893841449653
This commit is contained in:
Alessio Quaglino
2025-01-06 07:49:35 -08:00
committed by Copybara-Service
parent b5df2c10bf
commit f607d9554e
9 changed files with 37 additions and 15 deletions
+12
View File
@@ -1222,9 +1222,21 @@ void TestDetachBody(bool compile) {
mjsBody* body = mjs_findBody(child, "body");
EXPECT_THAT(body, NotNull());
// get an error if trying to delete the body
EXPECT_EQ(mjs_delete(body->element), -1);
EXPECT_THAT(mjs_getError(child), HasSubstr("use detach instead"));
// detach subtree
EXPECT_THAT(mjs_detachBody(child, body), 0);
// try saving to XML before compiling again
std::array<char, 1024> e;
std::array<char, 1024> s;
EXPECT_EQ(mj_saveXMLString(child, s.data(), 1024, e.data(), 1024), -1);
EXPECT_THAT(e.data(), compile
? HasSubstr("Model has pending keyframes")
: HasSubstr("Only compiled model can be written"));
// compile new model
mjModel* m_detached = mj_compile(child, 0);
EXPECT_THAT(m_detached, NotNull());