@@ -256,7 +256,9 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
256256#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
257257 LLSERemoveTimeTaskData (scriptEngine);
258258#endif
259- LLSECallEventsOnHotUnload (scriptEngine);
259+ if (ll::getGamingStatus () == ll::GamingStatus::Running) {
260+ LLSECallEventsOnHotUnload (scriptEngine);
261+ }
260262 LLSERemoveAllEventListeners (scriptEngine);
261263 LLSERemoveCmdRegister (scriptEngine);
262264 LLSERemoveCmdCallback (scriptEngine);
@@ -267,22 +269,22 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
267269
268270 eraseMod (name);
269271
270- if ( ll::getGamingStatus () != ll::GamingStatus::Running ) {
272+ auto destroyEngine = [scriptEngine]( ) {
271273#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
272274 NodeJsHelper::stopEngine (scriptEngine);
273275#else
274276 scriptEngine->destroy (); // TODO: use unique_ptr to manage the engine.
275277#endif
276- } else {
277- ll::coro::keepThis ([scriptEngine]() -> ll::coro::CoroTask<> {
278+ };
279+
280+ if (ll::getGamingStatus () == ll::GamingStatus::Running) {
281+ ll::coro::keepThis ([destroyEngine]() -> ll::coro::CoroTask<> {
278282 using namespace ll ::chrono_literals;
279283 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
284+ destroyEngine ();
285285 }).launch (ll::thread::ServerThreadExecutor::getDefault ());
286+ } else {
287+ destroyEngine ();
286288 }
287289
288290 return {};
0 commit comments