Skip to content

Commit 8941f56

Browse files
quaglacopybara-github
authored andcommitted
Copy UIDs during mj_copySpec.
This will produce the same mjSpec signature after a deep copy. PiperOrigin-RevId: 743538018 Change-Id: Ic0f5b06a00e8883cb92dc98159db3bea02cb7a36
1 parent 54f132f commit 8941f56

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/user/user_model.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void mjCModel::CopyList(std::vector<T*>& dest,
297297
// copy the element from the other model to this model
298298
if (deepcopy_) {
299299
source[i]->ForgetKeyframes();
300-
candidate->uid = GetUid();
300+
candidate->uid = source[i]->uid;
301301
} else {
302302
candidate->AddRef();
303303
}

src/user/user_objects.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ mjCBody::mjCBody(mjCModel* _model) {
840840

841841
mjCBody::mjCBody(const mjCBody& other, mjCModel* _model) {
842842
model = _model;
843-
uid = model->GetUid();
843+
uid = other.uid;
844844
mjSpec* origin = model->FindSpec(other.compiler);
845845
compiler = origin ? &origin->compiler : &model->spec.compiler;
846846
*this = other;
@@ -944,7 +944,7 @@ mjCBody& mjCBody::operator+=(const mjCFrame& other) {
944944
frames.back()->frame = other.frame;
945945
if (model->deepcopy_) {
946946
frames.back()->NameSpace(other_model);
947-
frames.back()->uid = model->GetUid();
947+
frames.back()->uid = other.uid;
948948
} else {
949949
frames.back()->AddRef();
950950
}
@@ -1038,7 +1038,7 @@ void mjCBody::CopyList(std::vector<T*>& dst, const std::vector<T*>& src,
10381038
if (!model->deepcopy_) {
10391039
dst.back()->AddRef();
10401040
} else {
1041-
dst.back()->uid = model->GetUid();
1041+
dst.back()->uid = src[i]->uid;
10421042
}
10431043

10441044
// set namespace

test/user/user_api_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ TEST_F(PluginTest, RecompileCompare) {
538538
// copy spec
539539
mjSpec* s_copy = mj_copySpec(s);
540540

541+
// compare signature
542+
EXPECT_EQ(s->element->signature, s_copy->element->signature) << xml;
543+
541544
// compile twice and compare
542545
mjModel* m_old = mj_compile(s, nullptr);
543546

0 commit comments

Comments
 (0)