Description
Components that have slaves (via l_slaves) do not have their destructors called during scene unload, even though cleanup() is called correctly.
Root Cause
BaseObject::l_slaves is defined with FLAG_STRONGLINK:
// BaseObject.h:134
typedef MultiLink<BaseObject, BaseObject, BaseLink::FLAG_DOUBLELINK|BaseLink::FLAG_STRONGLINK> LinkSlaves;
When a component (e.g., TetrahedronFEMForceField) has slaves (e.g., Stiffness_matrix, Damping_matrix created by the matrix assembly system), these strong references are never released during cleanup. This prevents the reference count from reaching zero, so the destructor is never called.
Steps to Reproduce
- Create a scene with TetrahedronFEMForceField (or any component that acquires slaves)
- Run with batch GUI: runSofa -g batch scene.scn
- Quit normally
- Observe that TetrahedronFEMForceField::~TetrahedronFEMForceField() is never called, while cleanup() is called
Expected Behavior
The destructor should be called after cleanup() when the scene is unloaded.
Workaround
Manually removing slaves in cleanup() fixes the issue:
void cleanup() override
{
while (!this->l_slaves.empty())
{
this->removeSlave(this->l_slaves.getValue().front());
}
Inherit1::cleanup();
}
Suggested Fix
BaseObject::cleanup() should automatically remove all slaves:
void BaseObject::cleanup()
{
while (!l_slaves.empty())
{
removeSlave(l_slaves.getValue().front());
}
}
Description
Components that have slaves (via
l_slaves) do not have their destructors called during scene unload, even thoughcleanup()is called correctly.Root Cause
BaseObject::l_slavesis defined withFLAG_STRONGLINK:When a component (e.g., TetrahedronFEMForceField) has slaves (e.g., Stiffness_matrix, Damping_matrix created by the matrix assembly system), these strong references are never released during cleanup. This prevents the reference count from reaching zero, so the destructor is never called.
Steps to Reproduce
Expected Behavior
The destructor should be called after cleanup() when the scene is unloaded.
Workaround
Manually removing slaves in cleanup() fixes the issue:
Suggested Fix
BaseObject::cleanup() should automatically remove all slaves: