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 | 192 | // Gracefully stop the engine's scripting thread |
| 193 | 193 | scriptEngine->stop(); |
| 194 | + removeScriptEngine(scriptEngine); | |
| 194 | 195 | |
| 195 | 196 | // We need to wait for the engine to be done running before we proceed, because we don't |
| 196 | 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 | 395 | // stop all scripts |
| 395 | 396 | qCDebug(scriptengine) << "stopping script..." << it.key(); |
| 396 | 397 | scriptEngine->stop(); |
| 398 | + removeScriptEngine(scriptEngine); | |
| 397 | 399 | } |
| 398 | 400 | // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before |
| 399 | 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 | 445 | scriptEngine->stop(); |
| 446 | + removeScriptEngine(scriptEngine); | |
| 444 | 447 | stoppedScript = true; |
| 445 | 448 | qCDebug(scriptengine) << "stopping script..." << scriptURL; |
| 446 | 449 | } |