Fix memory leak when reloading scripts

This commit is contained in:
David Rowe 2018-06-09 16:58:49 +12:00
parent 87e6df3cba
commit 9338c217cd

View file

@ -191,6 +191,7 @@ void ScriptEngines::shutdownScripting() {
// Gracefully stop the engine's scripting thread
scriptEngine->stop();
removeScriptEngine(scriptEngine);
// We need to wait for the engine to be done running before we proceed, because we don't
// want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
@ -394,6 +395,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
// stop all scripts
qCDebug(scriptengine) << "stopping script..." << it.key();
scriptEngine->stop();
removeScriptEngine(scriptEngine);
}
// wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before
// triggering reload of any Client scripts / Entity scripts
@ -438,6 +440,7 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
});
}
scriptEngine->stop();
removeScriptEngine(scriptEngine);
stoppedScript = true;
qCDebug(scriptengine) << "stopping script..." << scriptURL;
}