Don't save an empty <default/> section.
PiperOrigin-RevId: 520594748 Change-Id: Ib5e1eb3a93e9d579adeda1052a2c29d724d6b497
This commit is contained in:
committed by
Copybara-Service
parent
ddfcd3b325
commit
3f9defa8d0
@@ -1057,6 +1057,13 @@ void mjXWriter::Default(XMLElement* root, mjCDef* def) {
|
|||||||
OneActuator(elem, &def->actuator, par);
|
OneActuator(elem, &def->actuator, par);
|
||||||
if (!elem->FirstAttribute()) section->DeleteChild(elem);
|
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
|
// add children recursively
|
||||||
for (int i=0; i<(int)def->childid.size(); i++) {
|
for (int i=0; i<(int)def->childid.size(); i++) {
|
||||||
Default(section, model->defaults[def->childid[i]]);
|
Default(section, model->defaults[def->childid[i]]);
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ using ::testing::NotNull;
|
|||||||
|
|
||||||
using XMLWriterTest = MujocoTest;
|
using XMLWriterTest = MujocoTest;
|
||||||
|
|
||||||
|
TEST_F(XMLWriterTest, EmptyModel) {
|
||||||
|
static constexpr char xml[] = "<mujoco/>";
|
||||||
|
mjModel* model = LoadModelFromString(xml);
|
||||||
|
ASSERT_THAT(model, NotNull());
|
||||||
|
std::string saved_xml = SaveAndReadXml(model);
|
||||||
|
EXPECT_THAT(saved_xml, Not(HasSubstr("default")));
|
||||||
|
mj_deleteModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(XMLWriterTest, SavesMemory) {
|
TEST_F(XMLWriterTest, SavesMemory) {
|
||||||
{
|
{
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
|
|||||||
Reference in New Issue
Block a user