Don't save an empty <default/> section.

PiperOrigin-RevId: 520594748
Change-Id: Ib5e1eb3a93e9d579adeda1052a2c29d724d6b497
This commit is contained in:
Yuval Tassa
2023-03-30 03:50:29 -07:00
committed by Copybara-Service
parent ddfcd3b325
commit 3f9defa8d0
2 changed files with 16 additions and 0 deletions
+7
View File
@@ -1057,6 +1057,13 @@ void mjXWriter::Default(XMLElement* root, mjCDef* def) {
OneActuator(elem, &def->actuator, par);
if (!elem->FirstAttribute()) section->DeleteChild(elem);
// if top-level class has no members or children, delete it and return
if (def->parentid<0 && section->NoChildren() && def->childid.empty()) {
root->DeleteChild(section);
delete par;
return;
}
// add children recursively
for (int i=0; i<(int)def->childid.size(); i++) {
Default(section, model->defaults[def->childid[i]]);