Delete plugins when their corresponding objects are deleted, if their instance belonged the object.
Fixes #2061. PiperOrigin-RevId: 676402701 Change-Id: Ia4807d57a3763e2100702b7e7ec96c300d0a9cfb
This commit is contained in:
committed by
Copybara-Service
parent
f161b63a22
commit
f4381e12a2
@@ -269,6 +269,9 @@ void mjCMesh::CopyFromSpec() {
|
||||
mjCMesh::~mjCMesh() {
|
||||
if (center_) mju_free(center_);
|
||||
if (graph_) mju_free(graph_);
|
||||
if (spec.plugin.active && spec.plugin.instance_name->empty()) {
|
||||
model->DeleteElement(spec.plugin.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -516,6 +516,7 @@ void mjCModel::DeleteElement(mjsElement* el) {
|
||||
}
|
||||
|
||||
if (compiled) {
|
||||
ResetTreeLists(); // in case of a nested delete
|
||||
MakeLists(world);
|
||||
ProcessLists(/*checkrepeat=*/false);
|
||||
}
|
||||
@@ -586,6 +587,9 @@ void mjCModel::CopyFromSpec() {
|
||||
|
||||
// destructor
|
||||
mjCModel::~mjCModel() {
|
||||
// do not rebuild lists if we are in the process of deleting the model
|
||||
compiled = false;
|
||||
|
||||
// delete kinematic tree and all objects allocated in it
|
||||
delete bodies_[0];
|
||||
|
||||
|
||||
@@ -984,6 +984,10 @@ mjCBody::~mjCBody() {
|
||||
sites.clear();
|
||||
cameras.clear();
|
||||
lights.clear();
|
||||
|
||||
if (spec.plugin.active && spec.plugin.instance_name->empty()) {
|
||||
model->DeleteElement(spec.plugin.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2107,6 +2111,14 @@ mjCGeom::mjCGeom(const mjCGeom& other) {
|
||||
|
||||
|
||||
|
||||
mjCGeom::~mjCGeom() {
|
||||
if (spec.plugin.active && spec.plugin.instance_name->empty()) {
|
||||
model->DeleteElement(spec.plugin.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjCGeom& mjCGeom::operator=(const mjCGeom& other) {
|
||||
if (this != &other) {
|
||||
this->spec = other.spec;
|
||||
@@ -5521,6 +5533,14 @@ mjCActuator::mjCActuator(const mjCActuator& other) {
|
||||
|
||||
|
||||
|
||||
mjCActuator::~mjCActuator() {
|
||||
if (spec.plugin.active && spec.plugin.instance_name->empty()) {
|
||||
model->DeleteElement(spec.plugin.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjCActuator& mjCActuator::operator=(const mjCActuator& other) {
|
||||
if (this != &other) {
|
||||
this->spec = other.spec;
|
||||
@@ -5875,6 +5895,14 @@ mjCSensor::mjCSensor(const mjCSensor& other) {
|
||||
|
||||
|
||||
|
||||
mjCSensor::~mjCSensor() {
|
||||
if (spec.plugin.active && spec.plugin.instance_name->empty()) {
|
||||
model->DeleteElement(spec.plugin.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjCSensor& mjCSensor::operator=(const mjCSensor& other) {
|
||||
if (this != &other) {
|
||||
this->spec = other.spec;
|
||||
|
||||
@@ -511,6 +511,7 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
|
||||
mjCGeom(mjCModel* = nullptr, mjCDef* = nullptr);
|
||||
mjCGeom(const mjCGeom& other);
|
||||
mjCGeom& operator=(const mjCGeom& other);
|
||||
~mjCGeom();
|
||||
|
||||
using mjCBase::name;
|
||||
mjsGeom spec; // variables set by user
|
||||
@@ -1456,6 +1457,7 @@ class mjCActuator : public mjCActuator_, private mjsActuator {
|
||||
mjCActuator(mjCModel* = nullptr, mjCDef* = nullptr);
|
||||
mjCActuator(const mjCActuator& other);
|
||||
mjCActuator& operator=(const mjCActuator& other);
|
||||
~mjCActuator();
|
||||
|
||||
mjsActuator spec;
|
||||
using mjCBase::name;
|
||||
@@ -1516,6 +1518,7 @@ class mjCSensor : public mjCSensor_, private mjsSensor {
|
||||
mjCSensor(mjCModel*);
|
||||
mjCSensor(const mjCSensor& other);
|
||||
mjCSensor& operator=(const mjCSensor& other);
|
||||
~mjCSensor();
|
||||
|
||||
mjsSensor spec;
|
||||
using mjCBase::name;
|
||||
|
||||
Reference in New Issue
Block a user