Skip to content

Commit 69f8349

Browse files
quaglacopybara-github
authored andcommitted
Add signature error checking at the end of compilation.
Fixed some edge cases that caused the new error to be triggered. PiperOrigin-RevId: 740483759 Change-Id: I6ced3ba55476d5c18103e205151ecace94f2b29b
1 parent 157b074 commit 69f8349

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/user/user_model.cc

+25-6
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ mjCModel& mjCModel::operator=(const mjCModel& other) {
245245
mjCBody* world = new mjCBody(*other.bodies_[0], this);
246246
bodies_.push_back(world);
247247

248+
// update tree lists
249+
ResetTreeLists();
250+
MakeTreeLists();
251+
248252
// add everything else
249253
*this += other;
250254

@@ -259,6 +263,9 @@ mjCModel& mjCModel::operator=(const mjCModel& other) {
259263
for (int i=0; i < mjNOBJECT; i++) {
260264
ids[i] = other.ids[i];
261265
}
266+
267+
// update signature after we updated everything
268+
spec.element->signature = Signature();
262269
}
263270
deepcopy_ = other.deepcopy_;
264271
return *this;
@@ -504,10 +511,11 @@ mjCModel& mjCModel::operator+=(const mjCModel& other) {
504511
nq = nv = na = nu = nmocap = 0;
505512
}
506513

507-
// update signature before we reset the tree lists
508-
spec.element->signature = Signature();
509-
514+
// update pointers to local elements
510515
PointToLocal();
516+
517+
// update signature after we updated the tree lists and we updated the pointers
518+
spec.element->signature = Signature();
511519
return *this;
512520
}
513521

@@ -814,12 +822,12 @@ void mjCModel::DeleteElement(mjsElement* el) {
814822
break;
815823
}
816824

817-
// update signature before we reset the tree lists
818-
spec.element->signature = Signature();
819-
820825
ResetTreeLists(); // in case of a nested delete
821826
MakeTreeLists();
822827
ProcessLists(/*checkrepeat=*/false);
828+
829+
// update signature after we updated everything
830+
spec.element->signature = Signature();
823831
}
824832

825833

@@ -4593,6 +4601,17 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
45934601

45944602
// save signature
45954603
m->signature = Signature();
4604+
4605+
// special cases that are not caused by user edits
4606+
if (compiler.fusestatic || compiler.discardvisual ||
4607+
!spec.element->signature || !pairs_.empty() || !excludes_.empty()) {
4608+
spec.element->signature = m->signature;
4609+
}
4610+
4611+
// check that the signature matches the spec
4612+
if (m->signature != spec.element->signature) {
4613+
throw mjCError(0, "signature mismatch"); // SHOULD NOT OCCUR
4614+
}
45964615
}
45974616

45984617

src/user/user_objects.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ mjCFrame* mjCBody::ToFrame() {
14221422
parent->bodies.end());
14231423
model->ResetTreeLists();
14241424
model->MakeTreeLists();
1425+
model->spec.element->signature = model->Signature();
14251426
return newframe;
14261427
}
14271428

0 commit comments

Comments
 (0)