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:
Alessio Quaglino
2024-09-19 07:20:44 -07:00
committed by Copybara-Service
parent f161b63a22
commit f4381e12a2
5 changed files with 89 additions and 0 deletions
+28
View File
@@ -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;