pmed / v8pp

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

undefined V8PP_ISOLATE_DATA_SLOT will cause crash while exiting. #36

Closed Yangff closed 7 years ago

Yangff commented 7 years ago

I' upgrading from a old version of v8pp to current so I have this issue.

Finally, I found it is because I didn't set V8PP_ISOLATE_DATA_SLOT and it's using unordered_map.

std::unordered_map<v8::Isolate*, class_singletons> instances maybe not a good way for store v8 object since it will cleanup by CRT after v8 has been shutdown. For me, it crash while exiting.

Maybe these code can be just removed and force to use V8PP_ISOLATE_DATA_SLOT?

pmed commented 7 years ago

Hi @Yangff,

Yes, you should delete all V8 objects before V8 shutdown. There is a v8pp::class_<T>::destroy(v8::Isolate*) function to delete all wrapped C++ objects of class T and its binding in a V8 isolate, and v8pp::cleanup(v8::Isolate*) function to delete all class bindings in a V8 isolate.

This cleanup function is invoked in a v8pp::context destructor, but if you do not use v8pp contexts (say in a Node.js addon) you can cleanup v8pp in a node::AtExit() callback, as in example:

node::AtExit([](void* param) { v8pp::cleanup(static_cast<Isolate*>(param)); }, isolate);