pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
898 stars 120 forks source link

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

Closed scottd72 closed 7 years ago

scottd72 commented 7 years ago

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 commented 7 years ago

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

pmed commented 7 years ago

@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 commented 7 years ago

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