Skip to content

The python part of overloaded objects are deleted  #245

@damienmarchal

Description

@damienmarchal

The issue is related to python reference holding in overridable classes.

Some binded have a valid behavior (eg: Controller) but other don't (Prefab/RawPrefab)
The problem can be reproduced with the follwing scene:

import Sofa

class MyController(Sofa.Core.Controller):
    def __init__(self, *args, **kwargs):
        Sofa.Core.Controller.__init__(self,*args,**kwargs)
        print("Controller created")

    def __del__(self):
        print("Controller deleted")

class MyPrefab(Sofa.Core.RawPrefab):
    def __init__(self, *args, **kwargs):
        Sofa.Core.RawPrefab.__init__(self,*args,**kwargs)
        print("Prefab created")

    def __del__(self):
        print("Prefab deleted")

def createScene(root):
    root.addObject(MyController())    
    root.addChild(MyPrefab())   

The expected behavior is demonstrated by overriding a Controller, and the broken is implmented by overriding a Prefab.
The MyPrefab's destructor is called (which means that the reference count down to zero), while the controller's one is not.

This is related probably related to PR: #74
(Adding manually an extra reference to the python object solve the problem but is clearly is not the solution... I wonder if this is due to a misunderstanding in how the py_shared_ptr in Bindin_Prefab.cpp)

Any idea @jnbrunet, @fredroy ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions