Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 54 files). Show all
Unified · Split
| @@ -191,7 +191,6 @@ void ScriptEngines::shutdownScripting() { · 190 unmodified lines | ||
| 191 | 191 | |
| 192 | 192 | // Gracefully stop the engine's scripting thread |
| 193 | 193 | scriptEngine->stop(); |
| 194 | − removeScriptEngine(scriptEngine); | |
| 195 | 194 | |
| 196 | 195 | // We need to wait for the engine to be done running before we proceed, because we don't |
| 197 | 196 | // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing |
| @@ -375,13 +374,10 @@ QStringList ScriptEngines::getRunningScripts() { · 177 unmodified lines | ||
| 375 | 374 | } |
| 376 | 375 | |
| 377 | 376 | void ScriptEngines::stopAllScripts(bool restart) { |
| 378 | − QVector<QString> toReload; | |
| 379 | 377 | QReadLocker lock(&_scriptEnginesHashLock); |
| 380 | 378 | |
| 381 | 379 | if (_isReloading) { |
| 382 | 380 | return; |
| 383 | − } else { | |
| 384 | − _isReloading = true; | |
| 385 | 381 | } |
| 386 | 382 | |
| 387 | 383 | for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin(); |
| @@ -394,29 +390,27 @@ void ScriptEngines::stopAllScripts(bool restart) { · 6 unmodified lines | ||
| 394 | 390 | |
| 395 | 391 | // queue user scripts if restarting |
| 396 | 392 | if (restart && scriptEngine->isUserLoaded()) { |
| 397 | − toReload << it.key().toString(); | |
| 393 | + _isReloading = true; | |
| 394 | + bool lastScript = (it == _scriptEnginesHash.constEnd() - 1); | |
| 395 | + ScriptEngine::Type type = scriptEngine->getType(); | |
| 396 | + | |
| 397 | + connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) { | |
| 398 | + reloadScript(scriptName, true)->setType(type); | |
| 399 | + | |
| 400 | + if (lastScript) { | |
| 401 | + _isReloading = false; | |
| 402 | + } | |
| 403 | + }); | |
| 398 | 404 | } |
| 399 | 405 | |
| 400 | 406 | // stop all scripts |
| 401 | 407 | scriptEngine->stop(); |
| 402 | − removeScriptEngine(scriptEngine); | |
| 403 | 408 | } |
| 404 | − // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before | |
| 405 | − // triggering reload of any Client scripts / Entity scripts | |
| 406 | − QTimer::singleShot(1000, this, [=]() { | |
| 407 | − for(const auto &scriptName : toReload) { | |
| 408 | − auto scriptEngine = getScriptEngine(scriptName); | |
| 409 | − if (scriptEngine && !scriptEngine->isFinished()) { | |
| 410 | − scriptEngine->waitTillDoneRunning(); | |
| 411 | − } | |
| 412 | − reloadScript(scriptName); | |
| 413 | − } | |
| 414 | − if (restart) { | |
| 415 | − qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; | |
| 416 | − emit scriptsReloading(); | |
| 417 | − } | |
| 418 | − _isReloading = false; | |
| 419 | − }); | |
| 409 | + | |
| 410 | + if (restart) { | |
| 411 | + qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; | |
| 412 | + emit scriptsReloading(); | |
| 413 | + } | |
| 420 | 414 | } |
| 421 | 415 | |
| 422 | 416 | bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { |
| @@ -444,7 +438,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 21 unmodified lines | ||
| 444 | 438 | } |
| 445 | 439 | } |
| 446 | 440 | scriptEngine->stop(); |
| 447 | − removeScriptEngine(scriptEngine); | |
| 448 | 441 | stoppedScript = true; |
| 449 | 442 | } |
| 450 | 443 | } |