Skip to content

Commit a40a344

Browse files
committed
fix: try fix crash on unload
1 parent 245b616 commit a40a344

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/lse/PluginManager.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
249249
try {
250250
auto scriptEngine = EngineManager::getEngine(std::string(name));
251251

252+
if (!scriptEngine) {
253+
return ll::makeStringError("Plugin {0} not found"_tr(name));
254+
}
255+
252256
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
253257
LLSERemoveTimeTaskData(scriptEngine);
254258
#endif
@@ -263,15 +267,23 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
263267

264268
eraseMod(name);
265269

266-
ll::coro::keepThis([scriptEngine]() -> ll::coro::CoroTask<> {
267-
using namespace ll::chrono_literals;
268-
co_await 1_tick;
270+
if (ll::getGamingStatus() != ll::GamingStatus::Running) {
269271
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
270272
NodeJsHelper::stopEngine(scriptEngine);
271273
#else
272274
scriptEngine->destroy(); // TODO: use unique_ptr to manage the engine.
273275
#endif
274-
}).launch(ll::thread::ServerThreadExecutor::getDefault());
276+
} else {
277+
ll::coro::keepThis([scriptEngine]() -> ll::coro::CoroTask<> {
278+
using namespace ll::chrono_literals;
279+
co_await 1_tick;
280+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
281+
NodeJsHelper::stopEngine(scriptEngine);
282+
#else
283+
scriptEngine->destroy(); // TODO: use unique_ptr to manage the engine.
284+
#endif
285+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
286+
}
275287

276288
return {};
277289
} catch (const std::exception& e) {

0 commit comments

Comments
 (0)