James chen Help! Crash when doing evalString in cocos2dx 3.0 alpha1!

James chen Help! Crash when doing evalString in cocos2dx 3.0 alpha1!
0.0 0


I run a thread to read our input in win32 console,
and put the string to a list with lock.
I add a call in Application::run() to run a callback function every frame, to make sure the call back run in main thread.
The callback read a line from the list with lock and do like below:

void CmdHandler(const char* szCmd)
const char* c = szCmd;
while (*c != ‘\0’){
if (*c != ‘\t’ && *c!= ‘\n’ &&*c != ’ ') // check is empty
if (*c ‘’)
return; // empty
jsval val;
ScriptingCore::getInstance()->evalString(szText, &val, “cmd”); // crash!
ScriptingCore::log(ScriptingCore::getInstance()>getGlobalContext, 1, &val);
In cocos2dx 2.2, it works very well.
But it crash in a deep call stack in evalString
> JS_CompileScript every time, the crash call stack is different every time.

is there anything I can do to fix it?


I try

// in AppDelegate::applicationDidFinishLaunching()
#ifdef DEV
#endif // DEV

    jsval var;
    ScriptingCore::getInstance()->evalString("cc.log('work?')", &var);

the same thing happened.


Anybody get the same problem?


I will test it, thanks for your feedback.


I found out the reason:
Please move the JSAutoCompartment ac(cx, global); before JS_CompileScript.
I will submit a Pull Request to resolve it. Thanks.


The issue was created at http://www.cocos2d-x.org/issues/3273 .
Fixed at https://github.com/cocos2d/cocos2d-x/pull/4372.


Thank you~
Got\ it