You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement a virtual class i have in C++ using Python. To do that, I am using the trampoline as described in pybind documentation. The issue here is that in python, I need to keep the python object around or I would have a pure virtual function call error.
My python class looks like this
class BlendingField(PyVNCS.Sim2D.BlendingField):
def __init__(self):
PyVNCS.Sim2D.BlendingField.__init__(self)
def blending(self, point):
return 0.5
Basically, I create the BlendingField with the python implementation, I assign it to simCreator.blendingField property and I call simCreator.create(), which is a C++ function using the blending field.
If instead of doing it like that, I do it like this
I am trying to implement a virtual class i have in C++ using Python. To do that, I am using the trampoline as described in pybind documentation. The issue here is that in python, I need to keep the python object around or I would have a pure virtual function call error.
My python class looks like this
And I have to use like this
Basically, I create the BlendingField with the python implementation, I assign it to simCreator.blendingField property and I call simCreator.create(), which is a C++ function using the blending field.
If instead of doing it like that, I do it like this
I get a crash when trying to use the blending field from C++. This happens because the python object is destroyed.
Is this the expected behavior? I find it kind of confusing and it needs an extra line which most of the times you dont really want.
The text was updated successfully, but these errors were encountered: