Skip to content

Commit c60e0be

Browse files
committed
fix: fix unload crash #300
1 parent 290cde5 commit c60e0be

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/legacy/engine/EngineOwnData.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ struct EngineOwnData {
8585
return index;
8686
}
8787
inline bool removeUnloadCallback(int pIndex) { return unloadCallbacks.erase(pIndex); }
88+
89+
static void clearEngineObjects(ScriptEngine* engine) {
90+
EngineScope scope(engine);
91+
auto data = std::static_pointer_cast<EngineOwnData>(engine->getData());
92+
data->playerDataDB.clear();
93+
// LLSERemoveAllExportedFuncs(engine);
94+
}
8895
};
8996

9097
// Engine additional data

src/lse/PluginManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
235235
LLSERemoveCmdCallback(scriptEngine);
236236
LLSERemoveAllExportedFuncs(scriptEngine);
237237

238-
scriptEngine->getData().reset();
238+
EngineOwnData::clearEngineObjects(scriptEngine);
239239
EngineManager::unregisterEngine(scriptEngine);
240240
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
241241
NodeJsHelper::stopEngine(scriptEngine);
@@ -268,8 +268,8 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
268268
LLSERemoveCmdCallback(scriptEngine);
269269
LLSERemoveAllExportedFuncs(scriptEngine);
270270

271+
EngineOwnData::clearEngineObjects(scriptEngine);
271272
EngineManager::unregisterEngine(scriptEngine);
272-
scriptEngine->getData().reset();
273273

274274
if (auto plugin = std::static_pointer_cast<Plugin>(getMod(name))) {
275275
plugin->onUnload();

0 commit comments

Comments
 (0)