Reset tree indices before recompiling.

Fixes #1822.

PiperOrigin-RevId: 654762203
Change-Id: I7f656f7dad376d4899229a8741315c8f821bfa56
This commit is contained in:
Alessio Quaglino
2024-07-22 08:29:31 -07:00
committed by Copybara-Service
parent f62792594f
commit e79efa60d6
2 changed files with 33 additions and 0 deletions
+1
View File
@@ -3206,6 +3206,7 @@ mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m) {
bodies_[i]->subtreedofs = 0;
}
mjCBody* world = bodies_[0];
ResetTreeLists();
Clear();
bodies_.push_back(world);
}
+32
View File
@@ -186,6 +186,38 @@ TEST_F(PluginTest, RecompileCompare) {
}
}
TEST_F(PluginTest, RecompileEdit) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body>
<freejoint/>
<geom size=".1"/>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1000> er;
mjSpec *spec = mj_parseXMLString(xml, 0, er.data(), er.size());
EXPECT_THAT(spec, NotNull()) << er.data();
mjModel *m1 = mj_compile(spec, nullptr);
EXPECT_THAT(m1, NotNull());
// add a geom
mjsBody *world = mjs_findBody(spec, "world");
mjsGeom *geom = mjs_addGeom(world, nullptr);
geom->size[0] = 1;
// compile again
mjModel *m2 = mj_compile(spec, nullptr);
EXPECT_THAT(m2, NotNull());
mj_deleteModel(m1);
mj_deleteModel(m2);
mj_deleteSpec(spec);
}
// ------------------- test cache with modified assets -------------------------
TEST_F(PluginTest, RecompileCompareObjCache) {