-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Cannot get std::vector from binded member function having passed by reference std::vector as parameter #1230
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
Comments
In this specific case it would probably be a good idea to use (It looks like an omission that we don't have a As to the actual issue, one possible solution is avoid binding stl functions directly, but instead use thin lambda functions that wrap the stl functions rather than directly binding the stl functions. e.g. |
Hum, replacing the above |
Did you remove all the other |
I replaced
with |
I added a . |
Some other possibilities: You mentioned in the OP:
which makes me think there may be an issue here with compiler settings, i.e. the two Some other, perhaps less likely ideas: Are you inheriting from the class, or just using it directly? In case you are inheriting, are you remembering to call There could be an issue with the compiler used for Python vs the compiler you are using. (This is a sort of variation of my first point, but might also be an issue). |
I also stumbled about the missing |
Uh oh!
There was an error while loading. Please reload this page.
I have a dll
Core
,class __declspec(dllexport)
'ing a certain classX
. This class is in charge of some progressive calculation, successive values being kept track of in an "array". (I don't know yet whichc++
/python
structure is the best for what I am trying to achieve.) This "array" can either be 1) a member ofX
or 2) returned by a member function ofX
. I am using this dll in anotherpyd
dll,Binder
, which as its name indicates, is in charge of doing python bindings ofX
(c++
) member functions. Then Iimport
theBinder.pyd
dll in a python file, and I try to use python functions.At the beginning, the "array" wasn't a member of
X
, which had a functionvoid F(std::vector<double> & array)
in charge of updating the array, but any run of the python file using the binded python version ofF
was triggering an access violation, precisely wheneverresize
orpush_back
where called on thestd::vector<double>
. I binded btwstd::vector<double>
as follows :I tried
std::share_ptr<double>
+int
(size) instead, same type of issue as well. I suspect that my problem is ultimately caused by this :https://support.microsoft.com/en-us/help/172396/you-may-experience-an-access-violation-when-you-access-an-stl-object-t
though I don't really know how to put the proposed solution in practice in my case.
So that I have at the switch to keeping the "array" as a member of
X
, but I really don't know what the better structure to give to it to by able to easily bind itsget
function so that I coudl extract the "array" in my python code. (I would also like to have a c++ code recyclable enough in other c++ contexts, that is : I don't want to have the signature ofF
to be too muchpybind11
-dependent.)Remark : at the origin,
Core
andBinder
dll's were one single dll, and I wasn't having the acces violation error triggered at run time.The text was updated successfully, but these errors were encountered: