Skip to content

Update the branch from upstream/master + FIX the memory leaks + preserve SPtr's ownership #1

Open
damienmarchal wants to merge 10 commits intoScheiklP:memory_leakfrom
CRIStAL-PADR:pr-scheikp-memory
Open

Update the branch from upstream/master + FIX the memory leaks + preserve SPtr's ownership #1
damienmarchal wants to merge 10 commits intoScheiklP:memory_leakfrom
CRIStAL-PADR:pr-scheikp-memory

Conversation

@damienmarchal
Copy link

No description provided.

fredroy and others added 10 commits August 3, 2022 16:09
…ofa-framework#265)

* [Sofa.Core] Adds tests for linkpath in the test file Base.py and BaseData.py

* [SofaPython3] Add a LinkPath object in both the binding and plugin.

The existing syntax to make links in Sofa is the following one:
```python
node.addObject("MeshObjLoader", name="loader")
node.addObject("MechanicalObject", position=node.loader.position.getLinkPath())
```

In addition to be very verbose the getLinkPath() is returning a string (eg: "@/node/loader.position")
Representing linkpath with string has drawback as it force the two objects to be part of the
same simulation graph which is not always the case.

Example of code that does not work as expected:
```python
def MyPrefab(target):
	node = Sofa.Core.Node("MyPrefab")
	node.addObject("MeshObjLoader", name="loader")
	node2.addObject("MechanicalObject", position=target)
	return node

def createScene(root):
	root.addObject("MeshObjLoader", name="loader")
	root.addChild( MyPrefab(loader.position.getLinkPath()) )
```
It does not work because getLinkPath is returning a string, this string is then
used to makes a path query into the scene-graph to locate the object or the data
field to attach to.
But in this case as the object issuing the query is not in the same graph
the query fails.

To solve this issue this PR introduce a LinkPath object which is pointing to a sofa object.
This LinkPath object is exposed in python and can be used to make parenting between objects and data
without the need of graph to path then path to graph conversion (so it is also much faster..
but we don't really care here right ?).

For consistency with the "value" in data field the PR expose this link path
with a dedicated "linkpath" attribute.
So the code is now the following:
```python
root.addObject("MeshObjLoader", name="loader")
root.addChild("MechanicalObject", name="p1", position=root.loader.position.value)      # Copy the value
root.addChild("MechanicalObject", name="p2", position=root.loader.position.linkpath)   # Make a link between data without string query

root.addObject("Mapping", name="loader", input=p1.linkpath)
```

* [SofaPython3] LinkPath remove not needed condition while setting nullptr on a smart pointer.

* [FIXUP] Passager clandestin.

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

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* Update Binding_Node.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>
* [all] fix unused variables

* fix sign compare

* Update bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>
# Conflicts:
#	Plugin/src/SofaPython3/PythonFactory.cpp
#	bindings/Sofa/src/SofaPython3/Sofa/Core/Data/Binding_DataContainer.cpp
@damienmarchal damienmarchal changed the title Pr scheikp memory Update the branch from upstream/master + FIX the memory leaks + preserve SPtr's ownership Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants