我目前正在将jxcore嵌入到我的机器人系统程序中。当我测试嵌入api时,我生成了以下代码:
#include "stdafx.h"
#include "ScriptEngine.h"
#include <windows.h>
#include "thread"
#include "mutex"
int main(int argc, char **args) {
char* homeFolder = args[0];
JX_InitializeOnce(homeFolder);
JX_InitializeNewEngine();
JX_DefineMainFile("console.log('parent engine')");
JXValue obj;
// Parent engine created at main thread ,and JX_CreateEmptyObject worked ok!
JX_CreateEmptyObject(&obj);
JXValue global;
JX_GetGlobalObject(&global);
JX_SetNamedProperty(&global, "NativeBridge", &obj);
JX_Free(&obj);
JX_Free(&global);
JX_StartEngine();
//create a new engine instance and attach it to a new thread
thread t1 (create_new_engine);
t1.join();
Sleep(10 * 1000);
}
void create_new_engine() {
string homeFolder = "";
JX_InitializeNewEngine();
JX_DefineMainFile("console.log('sub engine')");
JX_StartEngine();
JXValue obj1;
// sub engine created at new thread ,and JX_CreateEmptyObject called fail!
//Exception thrown: read access violation.
//__imp_TlsGetValue(...) returned nullptr.
//program break at :
//JXCORE_EXTERN(bool)
//JX_CreateEmptyObject(JXValue *value) {
// node::commons *com = node::commons::getInstance();
JX_CreateEmptyObject(&obj1);
JXValue global;
JX_GetGlobalObject(&global);
JX_SetNamedProperty(&global, "NativeBridge", &obj1);
JX_Free(&obj1);
JX_Free(&global);
JX_Loop();
JX_StopEngine();
}
我的工作环境是:Windows 10,2015年视觉工作室,在Mac上运行vm融合
感谢。