-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/py collision obj #1457
Fix/py collision obj #1457
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1457 +/- ##
==========================================
+ Coverage 58.22% 58.23% +0.01%
==========================================
Files 412 412
Lines 29923 29923
==========================================
+ Hits 17422 17425 +3
+ Misses 12501 12498 -3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So reference counting of dart will be wrong here. Can this become a problem, or is this okay?
This would be okay for most of the cases. The only downside is that we cannot take advantage of using BodyNodePtr
, which ensures that the BodyNode
(and its Skeleton
) doesn't get deleted until we hold the BodyNodePtr
. So we have to make sure the BodyNode
(or Skeleton
) is not deleted to keep the raw pointer valid.
Should it be implemented via adding
BodyNodePtr
objects as well?
It'd be ideal as we already exposed the object in:
dart/python/dartpy/dynamics/Node.cpp
Lines 87 to 97 in 35bd08e
.def( | |
"getBodyNodePtr", | |
+[](dart::dynamics::Node* self) -> dart::dynamics::BodyNodePtr { | |
return self->getBodyNodePtr(); | |
}) | |
.def( | |
"getBodyNodePtr", | |
+[](const dart::dynamics::Node* self) | |
-> dart::dynamics::ConstBodyNodePtr { | |
return self->getBodyNodePtr(); | |
}) |
which currently causes runtime error:
>>> b.getBodyNodePtr()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Unable to convert function return value to a Python type! The signature was
(self: dartpy.dynamics.Node) -> dart::dynamics::TemplateBodyNodePtr<dart::dynamics::BodyNode>
I just found out that there is a mapping of dart/python/dartpy/dynamics/BodyNode.cpp Line 39 in 35bd08e
As far as I understand, the PYBIND11_DECLARE_HOLDER_TYPE macro will implicitly convert the representation, so by changing the return values from dart::dynamics::BodyNodePtr to dart::dynamics::BodyNode* implicit conversion of this holder type would take place. This seems to be the pybind11 way to embed custom smart pointers (https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html#custom-smart-pointers). But the implicit conversion would cause the reference counting object to run out of scope after the function call. This would defeat the purpose of having a reference counting object in the first place, right?
If we won't go this way, the other solution would be to implement
|
Good catch! As the holding type of dart/python/dartpy/dynamics/module.cpp Line 82 in 35bd08e Let me create a PR to resolve the runtime error. Then you can simply return |
Closing this PR in favor of #1465 |
Thank you for your efforts. |
Adds Python bindings to get more complete Contact/Collision information, especially to get
BodyNode
s involved in a particular contact viasomeContact.collisionObject1.getShapeFrame().getBodyNodePtr()
. The following changes are madeCollisionObject
's methods from C++ were completedCollisionObject
declaration added inpython/dartpy/collision/module.cpp
-> Collision objects can be used now from Python codegetBodyNodePtr()
fordartpy::dynamics::ShapeNode
. Here, a discussion may be needed. AsgetBodyNodePtr()
returns adart::dynamics::BodyNodePtr
(not implemented in dartpy yet) the easiest implementation was to return the rawBodyNode*
usinggetBodyNodePtr().get()
. So reference counting of dart will be wrong here. Can this become a problem, or is this okay? Should it be implemented via addingBodyNodePtr
objects as well?Before creating a pull request
Document new methods and classesclang-format
Before merging a pull request
CHANGELOG.md