Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 1 file). 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 |
| @@ -370,13 +369,10 @@ QStringList ScriptEngines::getRunningScripts() { · 172 unmodified lines | ||
| 370 | 369 | } |
| 371 | 370 | |
| 372 | 371 | void ScriptEngines::stopAllScripts(bool restart) { |
| 373 | − QVector<QString> toReload; | |
| 374 | 372 | QReadLocker lock(&_scriptEnginesHashLock); |
| 375 | 373 | |
| 376 | 374 | if (_isReloading) { |
| 377 | 375 | return; |
| 378 | − } else { | |
| 379 | − _isReloading = true; | |
| 380 | 376 | } |
| 381 | 377 | |
| 382 | 378 | for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin(); |
| @@ -389,29 +385,27 @@ void ScriptEngines::stopAllScripts(bool restart) { · 6 unmodified lines | ||
| 389 | 385 | |
| 390 | 386 | // queue user scripts if restarting |
| 391 | 387 | if (restart && scriptEngine->isUserLoaded()) { |
| 392 | − toReload << it.key().toString(); | |
| 388 | + _isReloading = true; | |
| 389 | + bool lastScript = (it == _scriptEnginesHash.constEnd() - 1); | |
| 390 | + ScriptEngine::Type type = scriptEngine->getType(); | |
| 391 | + | |
| 392 | + connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) { | |
| 393 | + reloadScript(scriptName, true)->setType(type); | |
| 394 | + | |
| 395 | + if (lastScript) { | |
| 396 | + _isReloading = false; | |
| 397 | + } | |
| 398 | + }); | |
| 393 | 399 | } |
| 394 | 400 | |
| 395 | 401 | // stop all scripts |
| 396 | 402 | scriptEngine->stop(); |
| 397 | − removeScriptEngine(scriptEngine); | |
| 398 | 403 | } |
| 399 | − // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before | |
| 400 | − // triggering reload of any Client scripts / Entity scripts | |
| 401 | − QTimer::singleShot(1000, this, [=]() { | |
| 402 | − for(const auto &scriptName : toReload) { | |
| 403 | − auto scriptEngine = getScriptEngine(scriptName); | |
| 404 | − if (scriptEngine && !scriptEngine->isFinished()) { | |
| 405 | − scriptEngine->waitTillDoneRunning(); | |
| 406 | − } | |
| 407 | − reloadScript(scriptName); | |
| 408 | − } | |
| 409 | − if (restart) { | |
| 410 | − qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; | |
| 411 | − emit scriptsReloading(); | |
| 412 | − } | |
| 413 | − _isReloading = false; | |
| 414 | − }); | |
| 404 | + | |
| 405 | + if (restart) { | |
| 406 | + qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; | |
| 407 | + emit scriptsReloading(); | |
| 408 | + } | |
| 415 | 409 | } |
| 416 | 410 | |
| 417 | 411 | bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { |
| @@ -439,7 +433,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 21 unmodified lines | ||
| 439 | 433 | } |
| 440 | 434 | } |
| 441 | 435 | scriptEngine->stop(); |
| 442 | − removeScriptEngine(scriptEngine); | |
| 443 | 436 | stoppedScript = true; |
| 444 | 437 | } |
| 445 | 438 | } |