Skip to content

Commit

Permalink
fix: 修复关闭引擎时Gc引发崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Dec 26, 2024
1 parent 5743938 commit 24a5d8c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Manager/NodeManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "env.h"
#include "fmt/core.h"
#include "nlohmann/json.hpp"
#include "node.h"
#include "uv/uv.h"
#include "v8-cppgc.h"
#include "v8/v8.h"
#include <filesystem>
#include <memory>
Expand Down Expand Up @@ -52,6 +54,15 @@ void NodeManager::initNodeJs() {
}

void NodeManager::shutdownNodeJs() {
for (auto& [id, wrapper] : mEngines) {
if (wrapper.mIsRunning) {
node::Stop(wrapper.mEnvSetup->env());
wrapper.mIsRunning = false;
}
}

// 清空引擎列表
mEngines.clear();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
}
Expand Down Expand Up @@ -90,8 +101,8 @@ EngineWrapper* NodeManager::newScriptEngine() {
EngineScope scope(engine);
BindAPI(engine); // 绑定API

EngineWrapper warpper{id, engine, std::move(envSetup)};
mEngines.insert({id, std::move(warpper)});
// EngineWrapper warpper;
mEngines.emplace(id, EngineWrapper{id, engine, std::move(envSetup)});

node::AddEnvironmentCleanupHook(
isolate,
Expand Down

0 comments on commit 24a5d8c

Please sign in to comment.