From 5913407491d4dd787a90575cef54044f9282ae83 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 11 Apr 2022 12:09:03 +0200 Subject: [PATCH] [SOfaPython/Binding] Add py::keep_alive in Binding_Node.cpp 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. --- bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp index 0dc0395b..137dca3e 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp @@ -529,12 +529,12 @@ void moduleAddNode(py::module &m) { p.def("add", &addKwargs, sofapython3::doc::sofa::core::Node::addKwargs); p.def("addObject", &addObjectKwargs, sofapython3::doc::sofa::core::Node::addObjectKwargs); p.def("addObject", &addObject, sofapython3::doc::sofa::core::Node::addObject, py::keep_alive<0, 2>()); - p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject); + p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject, py::keep_alive<0, 2>()); p.def("hasObject", &hasObject, sofapython3::doc::sofa::core::Node::hasObject); p.def("getObject", &getObject, sofapython3::doc::sofa::core::Node::getObject); p.def("addChild", &addChildKwargs, sofapython3::doc::sofa::core::Node::addChildKwargs); - p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild); - p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild); + p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild, py::keep_alive<0, 2>()); + p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild, py::keep_alive<0, 2>()); p.def("getChild", &getChild, sofapython3::doc::sofa::core::Node::getChild); p.def("removeChild", &removeChild, sofapython3::doc::sofa::core::Node::removeChild); p.def("removeChild", &removeChildByName, sofapython3::doc::sofa::core::Node::removeChildWithName);