Remove plugins that are not referenced after detaching a body.

Fixes #2497.

Also, use `Release()` instead of `delete` for removing elements when detaching a body in order to preserve correct reference count.

PiperOrigin-RevId: 739133888
Change-Id: I7ccfad84446fb15259bad30c4ba1e6f7fa601518
This commit is contained in:
Alessio Quaglino
2025-03-21 04:32:57 -07:00
committed by Copybara-Service
parent 8d92a0fbe6
commit dc96ed6bdb
3 changed files with 157 additions and 76 deletions
+8
View File
@@ -350,6 +350,9 @@ class mjCModel : public mjCModel_, private mjSpec {
void CopyPlugins(mjModel*); // copy plugin data
int CountNJmom(const mjModel* m); // compute number of non-zeros in actuator_moment matrix
// remove plugins that are not referenced by any object
void RemovePlugins();
// objects created here
std::vector<mjCFlex*> flexes_; // list of flexes
std::vector<mjCMesh*> meshes_; // list of meshes
@@ -430,6 +433,11 @@ class mjCModel : public mjCModel_, private mjSpec {
// return true if body has valid mass and inertia
bool CheckBodyMassInertia(mjCBody* body);
// Mark plugin instances mentioned in the list
template <class T>
void MarkPluginInstance(std::unordered_map<std::string, bool>& instances,
const std::vector<T*>& list);
mjListKeyMap ids; // map from object names to ids
mjCError errInfo; // last error info