mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 22:50:54 +02:00
fix interface crashing when reloading scripts
This commit is contained in:
parent
422045861a
commit
c4a9ca3445
1 changed files with 16 additions and 23 deletions
|
@ -191,7 +191,6 @@ void ScriptEngines::shutdownScripting() {
|
||||||
|
|
||||||
// Gracefully stop the engine's scripting thread
|
// Gracefully stop the engine's scripting thread
|
||||||
scriptEngine->stop();
|
scriptEngine->stop();
|
||||||
removeScriptEngine(scriptEngine);
|
|
||||||
|
|
||||||
// We need to wait for the engine to be done running before we proceed, because we don't
|
// 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
|
// want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
|
||||||
|
@ -370,13 +369,10 @@ QStringList ScriptEngines::getRunningScripts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngines::stopAllScripts(bool restart) {
|
void ScriptEngines::stopAllScripts(bool restart) {
|
||||||
QVector<QString> toReload;
|
|
||||||
QReadLocker lock(&_scriptEnginesHashLock);
|
QReadLocker lock(&_scriptEnginesHashLock);
|
||||||
|
|
||||||
if (_isReloading) {
|
if (_isReloading) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
_isReloading = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin();
|
for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin();
|
||||||
|
@ -389,29 +385,27 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
||||||
|
|
||||||
// queue user scripts if restarting
|
// queue user scripts if restarting
|
||||||
if (restart && scriptEngine->isUserLoaded()) {
|
if (restart && scriptEngine->isUserLoaded()) {
|
||||||
toReload << it.key().toString();
|
_isReloading = true;
|
||||||
|
bool lastScript = (it == _scriptEnginesHash.constEnd() - 1);
|
||||||
|
ScriptEngine::Type type = scriptEngine->getType();
|
||||||
|
|
||||||
|
connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) {
|
||||||
|
reloadScript(scriptName, true)->setType(type);
|
||||||
|
|
||||||
|
if (lastScript) {
|
||||||
|
_isReloading = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop all scripts
|
// stop all scripts
|
||||||
scriptEngine->stop();
|
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
|
|
||||||
QTimer::singleShot(1000, this, [=]() {
|
|
||||||
for(const auto &scriptName : toReload) {
|
|
||||||
auto scriptEngine = getScriptEngine(scriptName);
|
|
||||||
if (scriptEngine && !scriptEngine->isFinished()) {
|
|
||||||
scriptEngine->waitTillDoneRunning();
|
|
||||||
}
|
|
||||||
reloadScript(scriptName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restart) {
|
if (restart) {
|
||||||
qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading";
|
qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading";
|
||||||
emit scriptsReloading();
|
emit scriptsReloading();
|
||||||
}
|
}
|
||||||
_isReloading = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
||||||
|
@ -439,7 +433,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scriptEngine->stop();
|
scriptEngine->stop();
|
||||||
removeScriptEngine(scriptEngine);
|
|
||||||
stoppedScript = true;
|
stoppedScript = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue