Do not delete attached specs after compilation.

Also, copy them when copying the spec.

PiperOrigin-RevId: 688998464
Change-Id: I7229fd8032eafede582194ccf73ab4160fe06768
This commit is contained in:
Alessio Quaglino
2024-10-23 09:41:07 -07:00
committed by Copybara-Service
parent e14aebfd16
commit d17d9e835c
9 changed files with 95 additions and 10 deletions
+3 -6
View File
@@ -388,6 +388,9 @@ mjCModel& mjCModel::operator+=(const mjCModel& other) {
}
CopyList(numerics_, other.numerics_);
CopyList(texts_, other.texts_);
for (const auto* s : other.specs_) {
specs_.push_back(mj_copySpec(s));
}
}
CopyList(flexes_, other.flexes_);
CopyList(pairs_, other.pairs_);
@@ -3648,12 +3651,6 @@ mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m) {
return nullptr;
}
// destroy attached specs
for (auto spec : specs_) {
mj_deleteSpec(spec);
}
specs_.clear();
// restore error handler, mark as compiled, return mjModel
_mjPRIVATE__set_tls_error_fn(save_error);
_mjPRIVATE__set_tls_warning_fn(save_warning);
+2 -2
View File
@@ -387,11 +387,11 @@ mjSpec* ParseXML(const char* filename, const mjVFS* vfs,
return spec;
}
mjSpec* ParseSpecFromString(std::string_view xml, char* error, int nerror) {
mjSpec* ParseSpecFromString(std::string_view xml, const mjVFS* vfs, char* error, int nerror) {
RegisterResourceProvider();
std::string xml2 = {xml.begin(), xml.end()};
std::string str = "LoadModelFromString:" + xml2;
return ParseXML(str.c_str(), nullptr, error, nerror);
return ParseXML(str.c_str(), vfs, error, nerror);
}
// Main writer function - calls mjXWrite
+2 -1
View File
@@ -26,7 +26,8 @@ mjSpec* ParseXML(const char* filename, const mjVFS* vfs, char* error, int nerror
// Returns a newly-allocated mjSpec, loaded from the contents of xml.
// On failure returns nullptr and populates the error array if present.
mjSpec* ParseSpecFromString(std::string_view xml, char* error = nullptr, int nerror = 0);
mjSpec* ParseSpecFromString(std::string_view xml, const mjVFS* vfs = nullptr,
char* error = nullptr, int nerror = 0);
// Main writer function
std::string WriteXML(const mjModel* m, const mjSpec* spec, char* error, int nerror);
+1 -1
View File
@@ -221,7 +221,7 @@ mjSpec* mj_parseXML(const char* filename, const mjVFS* vfs, char* error, int err
// parse spec from string
mjSpec* mj_parseXMLString(const char* xml, const mjVFS* vfs, char* error, int error_sz) {
return ParseSpecFromString(xml, error, error_sz);
return ParseSpecFromString(xml, vfs, error, error_sz);
}