Copy UIDs during mj_copySpec.

This will produce the same mjSpec signature after a deep copy.

PiperOrigin-RevId: 743538018
Change-Id: Ic0f5b06a00e8883cb92dc98159db3bea02cb7a36
This commit is contained in:
Alessio Quaglino
2025-04-03 06:28:05 -07:00
committed by Copybara-Service
parent 54f132f3f0
commit 8941f56e86
3 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -297,7 +297,7 @@ void mjCModel::CopyList(std::vector<T*>& dest,
// copy the element from the other model to this model
if (deepcopy_) {
source[i]->ForgetKeyframes();
candidate->uid = GetUid();
candidate->uid = source[i]->uid;
} else {
candidate->AddRef();
}
+3 -3
View File
@@ -840,7 +840,7 @@ mjCBody::mjCBody(mjCModel* _model) {
mjCBody::mjCBody(const mjCBody& other, mjCModel* _model) {
model = _model;
uid = model->GetUid();
uid = other.uid;
mjSpec* origin = model->FindSpec(other.compiler);
compiler = origin ? &origin->compiler : &model->spec.compiler;
*this = other;
@@ -944,7 +944,7 @@ mjCBody& mjCBody::operator+=(const mjCFrame& other) {
frames.back()->frame = other.frame;
if (model->deepcopy_) {
frames.back()->NameSpace(other_model);
frames.back()->uid = model->GetUid();
frames.back()->uid = other.uid;
} else {
frames.back()->AddRef();
}
@@ -1038,7 +1038,7 @@ void mjCBody::CopyList(std::vector<T*>& dst, const std::vector<T*>& src,
if (!model->deepcopy_) {
dst.back()->AddRef();
} else {
dst.back()->uid = model->GetUid();
dst.back()->uid = src[i]->uid;
}
// set namespace
+3
View File
@@ -538,6 +538,9 @@ TEST_F(PluginTest, RecompileCompare) {
// copy spec
mjSpec* s_copy = mj_copySpec(s);
// compare signature
EXPECT_EQ(s->element->signature, s_copy->element->signature) << xml;
// compile twice and compare
mjModel* m_old = mj_compile(s, nullptr);