Fix memory leak when reloading scripts
Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 1 file). Show all
Unified · Split
| @@ -191,6 +191,7 @@ void ScriptEngines::shutdownScripting() { · 190 unmodified lines | |||
| 191 | 191 | ||
| 192 | // Gracefully stop the engine's scripting thread | 192 | // Gracefully stop the engine's scripting thread |
| 193 | scriptEngine->stop(); | 193 | scriptEngine->stop(); |
| 194 | removeScriptEngine(scriptEngine); | ||
| 194 | 195 | ||
| 195 | // We need to wait for the engine to be done running before we proceed, because we don't | 196 | // We need to wait for the engine to be done running before we proceed, because we don't |
| 196 | // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing | 197 | // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing |
| @@ -394,6 +395,7 @@ void ScriptEngines::stopAllScripts(bool restart) { · 197 unmodified lines | |||
| 394 | // stop all scripts | 395 | // stop all scripts |
| 395 | qCDebug(scriptengine) << "stopping script..." << it.key(); | 396 | qCDebug(scriptengine) << "stopping script..." << it.key(); |
| 396 | scriptEngine->stop(); | 397 | scriptEngine->stop(); |
| 398 | removeScriptEngine(scriptEngine); | ||
| 397 | } | 399 | } |
| 398 | // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before | 400 | // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before |
| 399 | // triggering reload of any Client scripts / Entity scripts | 401 | // triggering reload of any Client scripts / Entity scripts |
| @@ -441,6 +443,7 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 41 unmodified lines | |||
| 441 | } | 443 | } |
| 442 | } | 444 | } |
| 443 | scriptEngine->stop(); | 445 | scriptEngine->stop(); |
| 446 | removeScriptEngine(scriptEngine); | ||
| 444 | stoppedScript = true; | 447 | stoppedScript = true; |
| 445 | qCDebug(scriptengine) << "stopping script..." << scriptURL; | 448 | qCDebug(scriptengine) << "stopping script..." << scriptURL; |
| 446 | } | 449 | } |