Fix a bug in MuJoCo's user_mesh.cc that caused meshdir_ to be overwritten when a model was loaded with a nested model.

PiperOrigin-RevId: 675092713
Change-Id: Iad6336141749510bf5544cab9c06533ee1589c08
This commit is contained in:
Alessio Quaglino
2024-09-16 04:21:11 -07:00
committed by Copybara-Service
parent fd17b2144a
commit c77babe046
5 changed files with 116 additions and 9 deletions
+12 -4
View File
@@ -222,8 +222,12 @@ void mjCMesh::PointToLocal() {
void mjCMesh::NameSpace(const mjCModel* m) {
mjCBase::NameSpace(m);
modelfiledir_ = FilePath(m->spec_modelfiledir_);
meshdir_ = FilePath(m->spec_meshdir_);
if (modelfiledir_.empty()) {
modelfiledir_ = FilePath(m->spec_modelfiledir_);
}
if (meshdir_.empty()) {
meshdir_ = FilePath(m->spec_meshdir_);
}
}
@@ -2034,8 +2038,12 @@ void mjCSkin::NameSpace(const mjCModel* m) {
for (auto& name : spec_bodyname_) {
name = m->prefix + name + m->suffix;
}
modelfiledir_ = FilePath(m->spec_modelfiledir_);
meshdir_ = FilePath(m->spec_meshdir_);
if (modelfiledir_.empty()) {
modelfiledir_ = FilePath(m->spec_modelfiledir_);
}
if (meshdir_.empty()) {
meshdir_ = FilePath(m->spec_meshdir_);
}
}
+1
View File
@@ -607,6 +607,7 @@ mjCModel::~mjCModel() {
for (int i=0; i<tuples_.size(); i++) delete tuples_[i];
for (int i=0; i<keys_.size(); i++) delete keys_[i];
for (int i=0; i<defaults_.size(); i++) delete defaults_[i];
for (int i=0; i<specs_.size(); i++) mj_deleteSpec(specs_[i]);
if (plugin_owner) {
for (int i=0; i<plugins_.size(); i++) delete plugins_[i];
+12 -4
View File
@@ -3405,8 +3405,12 @@ void mjCHField::CopyFromSpec() {
void mjCHField::NameSpace(const mjCModel* m) {
mjCBase::NameSpace(m);
modelfiledir_ = FilePath(m->spec_modelfiledir_);
meshdir_ = FilePath(m->spec_meshdir_);
if (modelfiledir_.empty()) {
modelfiledir_ = FilePath(m->spec_modelfiledir_);
}
if (meshdir_.empty()) {
meshdir_ = FilePath(m->spec_meshdir_);
}
}
@@ -3650,8 +3654,12 @@ void mjCTexture::CopyFromSpec() {
void mjCTexture::NameSpace(const mjCModel* m) {
mjCBase::NameSpace(m);
modelfiledir_ = FilePath(m->spec_modelfiledir_);
texturedir_ = FilePath(m->spec_texturedir_);
if (modelfiledir_.empty()) {
modelfiledir_ = FilePath(m->spec_modelfiledir_);
}
if (texturedir_.empty()) {
texturedir_ = FilePath(m->spec_texturedir_);
}
}
-1
View File
@@ -3645,7 +3645,6 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
throw mjXError(0, "could not find body '%s''%s'", body_name.c_str());
}
if (mjs_attachBody(pframe, child, prefix.c_str(), "") != 0) {
mj_deleteSpec(asset);
throw mjXError(elem, mjs_getError(spec));
}
} else {