修改vscode第二次调试无法启动:Update JsEnv.cs
解决调试中打开预制体后, 下次无法调试 bug重现步骤: 打开unity打开场景, 运行游戏,调试vscode, 再打开其他预制体,代码逻辑会创建新的JeEnv的对象,关闭游戏 再运行游戏, 调试vscode时出现调试不了 原因: jeEnv的相应的调试没有关闭掉导致
https://github.com/Tencent/puerts/blob/master/unity/native_src/Src/JSEngine.cpp#L216 这个地方,DestroyJSEngine的时候本来就会关闭调试器,你的case下这句没产生效果?
JSEngine::~JSEngine() { if (Inspector) { delete Inspector; Inspector = nullptr; } Inspector 是有销毁, 但是下次调试时就无法执行
void JSEngine::DestroyInspector()
{
v8::Isolate* Isolate = MainIsolate;
v8::Isolate::Scope IsolateScope(Isolate);
v8::HandleScope HandleScope(Isolate);
v8::Local<v8::Context> Context = ResultInfo.Context.Get(Isolate);
v8::Context::Scope ContextScope(Context);
if (Inspector != nullptr)
{
delete Inspector;
Inspector = nullptr;
}
}
这个接口的
v8::Isolate* Isolate = MainIsolate;
v8::Isolate::Scope IsolateScope(Isolate);
v8::HandleScope HandleScope(Isolate);
v8::Localv8::Context Context = ResultInfo.Context.Get(Isolate);
v8::Context::Scope ContextScope(Context);
这些代码有什么用,
是不是要关闭调试对象Inspector , 需要调用了, 才能正常关闭调试
是为了创建一个JS上下文,这样才可以管理后续创建的js变量。 这里理论上应该是不需要创建Context的。
方便的话可以看看在DestroyJSEngine里delete Inspector之前,加上Context相关语句可以不可以 编译指南:https://github.com/Tencent/puerts/wiki/%5BUnity%5D-Plugin%E7%BC%96%E8%AF%91%E6%8C%87%E5%8D%97
在销毁时,调用 v8::Isolate* Isolate = MainIsolate; v8::Isolate::Scope IsolateScope(Isolate); v8::HandleScope HandleScope(Isolate); v8::Localv8::Context Context = ResultInfo.Context.Get(Isolate); v8::Context::Scope ContextScope(Context); 测试是可以正常的, 综合代码:就是在销毁时,调用void JSEngine::DestroyInspector() 从接口调用准则也应该是这两者相互呼应: 创建<=>销毁
好的,你把这个新的方式提交到PR里我就可以merge了哈。
我已经提交了pr了, 你看看,应该有收到pr请求
我看这个PR的内容还是你一开始提的方式,直接在csharp的~JsEnv里调PuertsDLL.DestroyInspector。
而不是在C++的~JSEngine,或者说PuertsDLL.DestroyJSEngine的时候调用DestroyInspector
你现在在C#的~JsEnv多调了一次PuertsDLL.DestroyInspector,就相当于整个销毁过程里有两段判断inspector存在并销毁的代码。
你可以在C++的~JSEngine 直接调用DestroyInspector的接口, 这样也行