Store the mjsCompiler -> appended mjSpec map when appending an mjSpec.

Previously, we stored the source `mjSpec` during a copy as a hack for having access to the compiler options, but this is not robust since we cannot guarantee that 1) the source `mjSpec` is not destroyed before we need to look up the compiler options nor 2) that the `mjSpec` was appended without a copy.

While 2) could be solved by simply handling an additional case in `mjCModel::FindSpec`, using a map also solves 1) and it is easier to understand.

PiperOrigin-RevId: 741504264
Change-Id: Iab1bfd9e61299a94fa8caf3a244c067b09d54384
This commit is contained in:
Alessio Quaglino
2025-03-28 06:26:30 -07:00
committed by Copybara-Service
parent 6e19035aab
commit 01d4c46753
4 changed files with 69 additions and 25 deletions
+2 -2
View File
@@ -904,7 +904,7 @@ mjCBody& mjCBody::operator+=(const mjCBody& other) {
mjCBody& mjCBody::operator+=(const mjCFrame& other) {
// append a copy of the attached spec
if (other.model != model && !model->FindSpec(mjs_getString(other.model->spec.modelname))) {
model->AppendSpec(mj_copySpec(&other.model->spec));
model->AppendSpec(mj_copySpec(&other.model->spec), &other.model->spec.compiler);
}
// create a copy of the subtree that contains the frame
@@ -2038,7 +2038,7 @@ mjCFrame& mjCFrame::operator=(const mjCFrame& other) {
mjCFrame& mjCFrame::operator+=(const mjCBody& other) {
// append a copy of the attached spec
if (other.model != model && !model->FindSpec(mjs_getString(other.model->spec.modelname))) {
model->AppendSpec(mj_copySpec(&other.model->spec));
model->AppendSpec(mj_copySpec(&other.model->spec), &other.model->spec.compiler);
}
// apply namespace and store keyframes in the source model