Automatically compile mjSpec in to_xml().

Also, move mj_compile from MjModelWrapper to MjSpec.

PiperOrigin-RevId: 737640210
Change-Id: I93d2a31c33eb359452b0d966a29939183b4c5198
This commit is contained in:
Alessio Quaglino
2025-03-17 09:20:29 -07:00
committed by Copybara-Service
parent 35774706ee
commit da04688071
7 changed files with 54 additions and 61 deletions
+3 -4
View File
@@ -246,15 +246,14 @@ int mj_saveXML(const mjSpec* s, const char* filename, char* error, int error_sz)
// if length of the output buffer is too small, returns the required size
int mj_saveXMLString(const mjSpec* s, char* xml, int xml_sz, char* error, int error_sz) {
std::string result = WriteXML(NULL, s, error, error_sz);
if (result.size() >= xml_sz) {
if (result.empty()) {
return -1;
} else if (result.size() >= xml_sz) {
std::string error_msg = "Output string too short, should be at least " +
std::to_string(result.size()+1);
mjCopyError(error, error_msg.c_str(), error_sz);
return result.size();
}
if (result.empty()) {
return -1;
}
result.copy(xml, xml_sz);
xml[result.size()] = 0;