mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-11 19:32:28 +02:00
Merge pull request #7942 from sethalves/fix-edit-js-restart
fix a race that keeps some scripts from restarting
This commit is contained in:
commit
485c8aceac
3 changed files with 15 additions and 6 deletions
|
@ -941,7 +941,13 @@ void ScriptEngine::stopAllTimersForEntityScript(const EntityItemID& entityID) {
|
|||
|
||||
}
|
||||
|
||||
void ScriptEngine::stop() {
|
||||
void ScriptEngine::stop(bool marshal) {
|
||||
_isStopping = true; // this can be done on any thread
|
||||
|
||||
if (marshal) {
|
||||
QMetaObject::invokeMethod(this, "stop");
|
||||
return;
|
||||
}
|
||||
if (!_isFinished) {
|
||||
_isFinished = true;
|
||||
emit runningStateChanged();
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// NOTE - this is intended to be a public interface for Agent scripts, and local scripts, but not for EntityScripts
|
||||
Q_INVOKABLE void stop();
|
||||
Q_INVOKABLE void stop(bool marshal = false);
|
||||
|
||||
// Stop any evaluating scripts and wait for the scripting thread to finish.
|
||||
void waitTillDoneRunning();
|
||||
|
@ -147,6 +147,9 @@ public:
|
|||
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
|
||||
bool isRunning() const { return _isRunning; } // used by ScriptWidget
|
||||
|
||||
// this is used by code in ScriptEngines.cpp during the "reload all" operation
|
||||
bool isStopping() const { return _isStopping; }
|
||||
|
||||
bool isDebuggable() const { return _debuggable; }
|
||||
|
||||
void disconnectNonEssentialSignals();
|
||||
|
@ -189,6 +192,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;
|
||||
|
|
|
@ -380,7 +380,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
|||
// Stop and possibly restart all currently running scripts
|
||||
for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
|
||||
it != _scriptEnginesHash.constEnd(); it++) {
|
||||
if (it.value()->isFinished()) {
|
||||
if (it.value()->isFinished() || it.value()->isStopping()) {
|
||||
continue;
|
||||
}
|
||||
if (restart && it.value()->isUserLoaded()) {
|
||||
|
@ -388,8 +388,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
|||
reloadScript(scriptName);
|
||||
});
|
||||
}
|
||||
QMetaObject::invokeMethod(it.value(), "stop");
|
||||
//it.value()->stop();
|
||||
it.value()->stop(true);
|
||||
qCDebug(scriptengine) << "stopping script..." << it.key();
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +459,7 @@ ScriptEngine* ScriptEngines::loadScript(const QUrl& scriptFilename, bool isUserL
|
|||
}
|
||||
|
||||
auto scriptEngine = getScriptEngine(scriptUrl);
|
||||
if (scriptEngine) {
|
||||
if (scriptEngine && !scriptEngine->isStopping()) {
|
||||
return scriptEngine;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue