Raise error when binding to a removed element.

PiperOrigin-RevId: 774462737
Change-Id: I820c0e1c010ae9fbf6d9667c3364d4b65bf21002
This commit is contained in:
Alessio Quaglino
2025-06-22 10:14:40 -07:00
committed by Copybara-Service
parent 419cdf1ff3
commit a00bfa819c
9 changed files with 19 additions and 77 deletions
+1 -12
View File
@@ -746,7 +746,6 @@ void mjCModel::DeleteSubtreePlugin(mjCBody* subtree) {
mjsPlugin* plugin = &(subtree->spec.plugin);
if (plugin->active && plugin->name->empty()) {
*this -= plugin->element;
detached_.push_back(static_cast<mjCBase*>(plugin->element));
}
for (auto* body : subtree->Bodies()) {
DeleteSubtreePlugin(body);
@@ -755,13 +754,6 @@ void mjCModel::DeleteSubtreePlugin(mjCBody* subtree) {
// delete an object from the model
void mjCModel::DeleteElement(mjsElement* el) {
static_cast<mjCBase*>(el)->Release();
}
// remove the element from the model
void mjCModel::operator-=(mjsElement* el) {
if (el->elemtype == mjOBJ_BODY) {
@@ -769,6 +761,7 @@ void mjCModel::operator-=(mjsElement* el) {
*this -= *body;
}
detached_.push_back(static_cast<mjCBase*>(el));
ResetTreeLists();
if (el->elemtype != mjOBJ_DEFAULT) {
@@ -800,7 +793,6 @@ void mjCModel::operator-=(mjsElement* el) {
mjCGeom* geom = static_cast<mjCGeom*>(el);
if (geom->plugin.active && geom->plugin.name->empty()) {
*this -= geom->plugin.element;
detached_.push_back(static_cast<mjCBase*>(geom->plugin.element));
}
deletefromlist(&(geom->body->geoms), el);
break;
@@ -827,7 +819,6 @@ void mjCModel::operator-=(mjsElement* el) {
mjCMesh* mesh = static_cast<mjCMesh*>(el);
if (mesh->plugin.active && mesh->plugin.name->empty()) {
*this -= mesh->plugin.element;
detached_.push_back(static_cast<mjCBase*>(mesh->plugin.element));
}
deletefromlist(object_lists_[mjOBJ_MESH], el);
break;
@@ -838,7 +829,6 @@ void mjCModel::operator-=(mjsElement* el) {
mjCActuator* actuator = static_cast<mjCActuator*>(el);
if (actuator->plugin.active && actuator->plugin.name->empty()) {
*this -= actuator->plugin.element;
detached_.push_back(static_cast<mjCBase*>(actuator->plugin.element));
}
deletefromlist(object_lists_[mjOBJ_ACTUATOR], el);
break;
@@ -849,7 +839,6 @@ void mjCModel::operator-=(mjsElement* el) {
mjCSensor* sensor = static_cast<mjCSensor*>(el);
if (sensor->plugin.active && sensor->plugin.name->empty()) {
*this -= sensor->plugin.element;
detached_.push_back(static_cast<mjCBase*>(sensor->plugin.element));
}
deletefromlist(object_lists_[mjOBJ_SENSOR], el);
break;