Skip to content
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

Forced garbage collection causes assertion failure if you try adding a std::function to a module #30

Closed
scottd72 opened this issue Oct 17, 2016 · 3 comments

Comments

@scottd72
Copy link

If I try adding a std::function to a v8pp module, and then force a final garbage collection before disposing of the isolate (which generally appears to be necessary if you're worried about making sure all embedded C++ objects get garbage collected, since merely disposing of the isolate doesn't guarantee all the weak callbacks v8pp registers are actually called), I get an assertion failure ("Check failed: node_->state() == Node::FREE.") later when trying to actually disposing of the isolate.

This doesn't happen (i.e., no assertion failure triggers) if I add either a C++ function or a lambda to the module instead of a std::function.

Test program illustrating the crash attached: v8_gc_crash.txt

@pmed
Copy link
Owner

pmed commented Oct 18, 2016

Hi @scottd72, thank you for reporting the issue. I will look there in the near days.

pmed added a commit that referenced this issue Oct 18, 2016
…30)

Added `external_data<T>` template class to store user data of type T when
sizeof(T) > sizeof(void*) and weak handle to v8::External with value pointing
to such an external_data instance.

User data are stored in std::aligned_storage<sizeof T> data member of
external_data instance and being deleted in the weak handle callback.

Updated function, module, class, and property wrappers to accept universal
references to binding entities to avoid making of unnecessary copies.
@pmed
Copy link
Owner

pmed commented Oct 19, 2016

@scottd72, I've changed internal data storage for wrapped C++ callable objects with sizeof greater than sizeof pointer (e.g. lambdas with captured values, std::function objects, user-defined classes with operator() ) and it seems has fixed this issue.

At least I hope so, since my tests and your program works now without assertion failures.

@scottd72
Copy link
Author

Wow...that was fast, and it looks like it did indeed make my assertion failure go away. Great! Thanks!

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

No branches or pull requests

2 participants