mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:24:03 +02:00
fix a race when restarting scripts -- avoid the old not-yet-stopped script from being considered the restart script
This commit is contained in:
parent
d0c883f75a
commit
4e862941cb
2 changed files with 6 additions and 1 deletions
|
@ -146,6 +146,8 @@ public:
|
|||
|
||||
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
|
||||
bool isRunning() const { return _isRunning; } // used by ScriptWidget
|
||||
bool isStopping() const { return _isStopping; }
|
||||
void flagAsStopping() { _isStopping = true; }
|
||||
|
||||
bool isDebuggable() const { return _debuggable; }
|
||||
|
||||
|
@ -189,6 +191,7 @@ protected:
|
|||
QString _parentURL;
|
||||
std::atomic<bool> _isFinished { false };
|
||||
std::atomic<bool> _isRunning { false };
|
||||
std::atomic<bool> _isStopping { false };
|
||||
int _evaluatesPending { 0 };
|
||||
bool _isInitialized { false };
|
||||
QHash<QTimer*, CallbackData> _timerFunctionMap;
|
||||
|
|
|
@ -351,6 +351,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
|||
reloadScript(scriptName);
|
||||
});
|
||||
}
|
||||
it.value()->flagAsStopping();
|
||||
QMetaObject::invokeMethod(it.value(), "stop");
|
||||
//it.value()->stop();
|
||||
qCDebug(scriptengine) << "stopping script..." << it.key();
|
||||
|
@ -369,6 +370,7 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
|||
if (_scriptEnginesHash.contains(scriptURL)) {
|
||||
ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURL];
|
||||
if (restart) {
|
||||
scriptEngine->flagAsStopping();
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->deleteScript(scriptURL);
|
||||
connect(scriptEngine, &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) {
|
||||
|
@ -454,7 +456,7 @@ ScriptEngine* ScriptEngines::getScriptEngine(const QUrl& rawScriptURL) {
|
|||
QReadLocker lock(&_scriptEnginesHashLock);
|
||||
const QUrl scriptURL = normalizeScriptURL(rawScriptURL);
|
||||
auto it = _scriptEnginesHash.find(scriptURL);
|
||||
if (it != _scriptEnginesHash.end()) {
|
||||
if (it != _scriptEnginesHash.end() && !it.value()->isStopping()) {
|
||||
result = it.value();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue