Basic js binding code crashes.


#1

Hi,everyone

I want to use js-binding in my project so I followed the tutorial and wrote the very basic js binding code for a test.
I used the js-binding template for my project so in the code it already had some js registration code for the engine:
i put my js registration code ahead of the existing js registration code:
+sc~~>addRegisterCallback;+ //my js class registration
sc~~>addRegisterCallback(register_all_cocos2dx);
sc~~>addRegisterCallback;
sc~~>addRegisterCallback(register_all_cocos2dx_extension_manual);
sc~~>addRegisterCallback;
sc~~>addRegisterCallback(register_CCBuilderReader);
sc~~>addRegisterCallback;
sc~~>addRegisterCallback(jsb_register_system);
sc~~>addRegisterCallback;
sc~~>addRegisterCallback(MinXmlHttpRequest::_js_register);
sc->addRegisterCallback(register_jsb_websocket);

in this case, I saw my js invoking and callbacks all work, but the problem comes when I close the application and it crashes at ScriptingCore::cleanup():
js_type_class_t* current, *tmp;
HASH_ITER(hh, _js_global_type_ht, current, tmp)
{
HASH_DEL(_js_global_type_ht, current);
free(current->jsclass);
free(current);//this is where it crashes………………
}
HASH_CLEAR(hh, _js_global_type_ht);

I checked the pointer address and found it crashed when clearing my js type, and deeper in the callstack it crashed at CrtIsValidHeapPointer() function….

I checked my js binding code, I even did comparison with the existing js registration code and couldn’t find the answer to this issuse.

So the js binding code worked but then the ‘type’ address became invalid??

Any thoughts shared would be appreciated


#2

Did it crash if you didn’t register your classes?


#3

hi,James

It doesn’t crash if i don’t register my classes, and one more clue is, if I comment out all the other registrations and leave only my own ‘sc->addRegisterCallback(register_all);’, then it doesn’t crash.

Any idea why this happens?

Thanks.


#4

simon pan wrote a very clear toturial at

I followed the instatruction and create jsb without any problem