Skip to content

Commit 98c8cb2

Browse files
[SOfaPython/Binding] Add py::keep_alive in Binding_Node.cpp (#248)
The object created from python needs special care to avoid being deleted by the python garbage collection mecanisme. In #74 and #75 the smart pointer mecanism was refactored. The refactoring added a py::keep_alive, in addObject but didn't in other functions. The PR fix this.
1 parent 69a634a commit 98c8cb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,12 @@ void moduleAddNode(py::module &m) {
529529
p.def("add", &addKwargs, sofapython3::doc::sofa::core::Node::addKwargs);
530530
p.def("addObject", &addObjectKwargs, sofapython3::doc::sofa::core::Node::addObjectKwargs);
531531
p.def("addObject", &addObject, sofapython3::doc::sofa::core::Node::addObject, py::keep_alive<0, 2>());
532-
p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject);
532+
p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject, py::keep_alive<0, 2>());
533533
p.def("hasObject", &hasObject, sofapython3::doc::sofa::core::Node::hasObject);
534534
p.def("getObject", &getObject, sofapython3::doc::sofa::core::Node::getObject);
535535
p.def("addChild", &addChildKwargs, sofapython3::doc::sofa::core::Node::addChildKwargs);
536-
p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild);
537-
p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild);
536+
p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild, py::keep_alive<0, 2>());
537+
p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild, py::keep_alive<0, 2>());
538538
p.def("getChild", &getChild, sofapython3::doc::sofa::core::Node::getChild);
539539
p.def("removeChild", &removeChild, sofapython3::doc::sofa::core::Node::removeChild);
540540
p.def("removeChild", &removeChildByName, sofapython3::doc::sofa::core::Node::removeChildWithName);

0 commit comments

Comments
 (0)