-
Notifications
You must be signed in to change notification settings - Fork 85
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
Binding a callback (std::function) causes runtime error #31
Comments
I'm not a JS expert, but maybe Listener's constructor is not getting called? |
Thanks for your reply ftk.
If so, I am happy to continue to look for a solution to where I have gone wrong! As long as you don't see any reason the library won't support it? :) |
@projectitis are you showing your full code? need a super in this constructor, without can cause errors like yours
|
No, sorry, it was just a snippet showing what my intentions are. Super is called in my actual code. |
Update: std::function works ok if the arguments and return type are non-custom types such as int, double, string etc. What might I be doing wrong? I'd like to get the second example to work. Working example:
Non-working example. This is what I would like to achieve. Compiles, but unexpected runtime result (empty object):
Non-working example, just for kicks. Does not compile. The only code change is that the callback argument is of Event type, not Event*.
|
The second example works for me. |
Wow, so strange. It's obviously something my side. Edit: |
I have been able to reproduce it.
And the In my case I have many event types that all extend Event (MouseEvent, ResizeEvent etc) hence the virtual destructor (and other virtual methods). |
This just got weird. Digging a little deeper, it looks like the virtual destructor somehow causes
See this updated gist: https://gist.github.com/projectitis/b8ab7ee70b3d58fe82731cdd138fc001 Any idea where/why this is happening? EDIT:
EDIT 2:
So another workaround I have is a throw-away property in my class. This works:
|
Still can't reproduce the bug from the gist: |
I'm compiling with visual studio 2019 using clang-cl (the one that ships with MSVC) on windows 10 (targeting x64). I've built quickjs v2021-03-27 from https://github.com/c-smile/quickjspp (because it purported to support visual studio) though I still had to modify the code to compile using clang (mostly swapping out POSIX functions for their non-POSIX named equivalents). If it works for you, that's a good sign for me - it means I can solve it :) EDIT: One of my dependencies (Skia) relies on clang for optimum performance. so I've tried to use clang to compile everything to ensure compatibility. So far it's been ok, but it's a real pain on windows when everything is generally set up to compile with MSVC. |
Hi again,
I'm trying to implement a callback in javascript that can be triggered from c++.
This is what I am trying to do:
Binding like this compiles ok:
But this javascript code causes a runtime exception:
The exception occurs in the
Value
constructor:Any ideas how to get (something like) this to work?
The text was updated successfully, but these errors were encountered: