Raise error when binding to a removed element.
PiperOrigin-RevId: 774462737 Change-Id: I820c0e1c010ae9fbf6d9667c3364d4b65bf21002
This commit is contained in:
committed by
Copybara-Service
parent
419cdf1ff3
commit
a00bfa819c
+2
-25
@@ -341,28 +341,6 @@ int mj_copyBack(mjSpec* s, const mjModel* m) {
|
||||
|
||||
|
||||
// detach body from mjSpec, return 0 on success
|
||||
int mjs_detach(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
if (!element) {
|
||||
model->SetError(mjCError(0, "Element is null."));
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
if (element->elemtype == mjOBJ_DEFAULT) {
|
||||
throw mjCError(0, "Detach is not implemented for defaults.");
|
||||
} else {
|
||||
*model -= element;
|
||||
}
|
||||
return 0;
|
||||
} catch (mjCError& e) {
|
||||
model->SetError(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// delete object, return 0 on success
|
||||
int mjs_delete(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
if (!element) {
|
||||
@@ -374,8 +352,7 @@ int mjs_delete(mjSpec* s, mjsElement* element) {
|
||||
mjCDef* def = static_cast<mjCDef*>(element);
|
||||
*model -= *def;
|
||||
} else {
|
||||
mjs_detach(s, element);
|
||||
model->DeleteElement(element);
|
||||
*model -= element;
|
||||
}
|
||||
return 0;
|
||||
} catch (mjCError& e) {
|
||||
@@ -1031,7 +1008,7 @@ const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* s
|
||||
mjsFrame* mjs_bodyToFrame(mjsBody** body) {
|
||||
mjCBody* bodyC = static_cast<mjCBody*>((*body)->element);
|
||||
mjCFrame* frameC = bodyC->ToFrame();
|
||||
bodyC->model->DeleteElement((*body)->element);
|
||||
*bodyC->model -= (*body)->element;
|
||||
*body = nullptr;
|
||||
return &frameC->spec;
|
||||
}
|
||||
|
||||
+1
-3
@@ -76,8 +76,6 @@ MJAPI int mj_copyBack(mjSpec* s, const mjModel* m);
|
||||
MJAPI mjsElement* mjs_attach(mjsElement* parent, const mjsElement* child,
|
||||
const char* prefix, const char* suffix);
|
||||
|
||||
// Detach but not delete object corresponding to the given element, return 0 on success.
|
||||
MJAPI int mjs_detach(mjSpec* s, mjsElement* element);
|
||||
|
||||
//---------------------------------- Add tree elements ---------------------------------------------
|
||||
|
||||
@@ -105,7 +103,7 @@ MJAPI mjsLight* mjs_addLight(mjsBody* body, const mjsDefault* def);
|
||||
// Add frame to body.
|
||||
MJAPI mjsFrame* mjs_addFrame(mjsBody* body, mjsFrame* parentframe);
|
||||
|
||||
// Delete object corresponding to the given element, return 0 on success.
|
||||
// Detach but not delete object corresponding to the given element, return 0 on success.
|
||||
MJAPI int mjs_delete(mjSpec* s, mjsElement* element);
|
||||
|
||||
|
||||
|
||||
+1
-12
@@ -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;
|
||||
|
||||
@@ -229,9 +229,6 @@ class mjCModel : public mjCModel_, private mjSpec {
|
||||
// delete object from the corresponding list
|
||||
void operator-=(mjsElement* el);
|
||||
|
||||
// delete object
|
||||
void DeleteElement(mjsElement* el);
|
||||
|
||||
// delete default and all descendants
|
||||
void RemoveDefault(mjCDef* def);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user