Require prefix for the attach tag.

For `mjs_attachFrame` and `mjs_attachBody`, require either a prefix or suffix.

It is tempting for users to not use a prefix (see #2162), but this causes issues. For example, it creates a duplicate "main" default class in the parent as a child of the already existing "main" default.

PiperOrigin-RevId: 688535755
Change-Id: I653181ca35943f1e4eb89c70fca8b5289818324e
This commit is contained in:
Alessio Quaglino
2024-10-22 07:07:33 -07:00
committed by Copybara-Service
parent 94e9912d28
commit bfa78614c8
5 changed files with 23 additions and 15 deletions
+8
View File
@@ -850,6 +850,10 @@ mjCBody& mjCBody::operator+=(const mjCFrame& other) {
other.model->suffix = other.suffix;
other.model->StoreKeyframes(model);
if (other.prefix.empty() && other.suffix.empty()) {
throw mjCError(this, "either prefix or suffix must be non-empty");
}
// attach defaults
if (other.model != model) {
mjCDef* subdef = new mjCDef(*other.model->Default());
@@ -1812,6 +1816,10 @@ mjCFrame& mjCFrame::operator+=(const mjCBody& other) {
other.model->prefix = "";
other.model->suffix = "";
if (other.prefix.empty() && other.suffix.empty()) {
throw mjCError(this, "either prefix or suffix must be non-empty");
}
mjCBody* subtree = new mjCBody(other, model);
other.ForgetKeyframes();
other.model->prefix = subtree->prefix;