Skip to content

Component destructors not called when slaves are present #5890

@fredroy

Description

@fredroy

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

  1. Create a scene with TetrahedronFEMForceField (or any component that acquires slaves)
  2. Run with batch GUI: runSofa -g batch scene.scn
  3. Quit normally
  4. 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());
      }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bug (major)Critical bug affecting everyone: not working, performances or accuracy degraded

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions