Check for duplicated names when setting element names.

PiperOrigin-RevId: 778827590
Change-Id: I77a208c1571cf735cae80840ea830aa347681f71
This commit is contained in:
Alessio Quaglino
2025-07-03 03:19:51 -07:00
committed by Copybara-Service
parent 594e17074a
commit 564c51ddb9
12 changed files with 96 additions and 74 deletions
+9 -2
View File
@@ -1342,14 +1342,21 @@ mjsPlugin* mjs_asPlugin(mjsElement* element) {
// set element name
void mjs_setName(mjsElement* element, const char* name) {
int mjs_setName(mjsElement* element, const char* name) {
if (element->elemtype == mjOBJ_DEFAULT) {
mjCDef* def = static_cast<mjCDef*>(element);
def->name = std::string(name);
return;
return 0;
}
mjCBase* baseC = static_cast<mjCBase*>(element);
baseC->name = std::string(name);
try {
baseC->model->CheckRepeat(element->elemtype);
} catch (mjCError& e) {
baseC->model->SetError(e);
return -1;
}
return 0;
}