some CR feedback

This commit is contained in:
ZappoMan 2016-04-30 15:23:50 -07:00
parent 48e63ea828
commit 73ff0308a9
2 changed files with 12 additions and 1 deletions

View file

@ -140,6 +140,8 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
connect(this, &QScriptEngine::signalHandlerException, this, [this](const QScriptValue& exception) { connect(this, &QScriptEngine::signalHandlerException, this, [this](const QScriptValue& exception) {
hadUncaughtExceptions(*this, _fileNameString); hadUncaughtExceptions(*this, _fileNameString);
}); });
setProcessEventsInterval(MSECS_PER_SECOND);
} }
ScriptEngine::~ScriptEngine() { ScriptEngine::~ScriptEngine() {
@ -193,6 +195,14 @@ void ScriptEngine::runInThread() {
workerThread->start(); workerThread->start();
} }
void ScriptEngine::threadSafeAbortEvaluation() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "threadSafeAbortEvaluation");
return;
}
abortEvaluation();
}
void ScriptEngine::waitTillDoneRunning() { void ScriptEngine::waitTillDoneRunning() {
// If the script never started running or finished running before we got here, we don't need to wait for it // If the script never started running or finished running before we got here, we don't need to wait for it
if (_isRunning && _isThreaded) { if (_isRunning && _isThreaded) {
@ -213,7 +223,7 @@ void ScriptEngine::waitTillDoneRunning() {
// if we've been waiting a second or more, then tell the script engine to stop evaluating // if we've been waiting a second or more, then tell the script engine to stop evaluating
if (elapsed > USECS_PER_SECOND) { if (elapsed > USECS_PER_SECOND) {
qDebug() << "giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation() script:" << scriptName; qDebug() << "giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation() script:" << scriptName;
abortEvaluation(); threadSafeAbortEvaluation();
} }
// if we've been waiting for more than 5 seconds then we should be more aggessive about stopping // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping

View file

@ -134,6 +134,7 @@ public:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE - this is intended to be a public interface for Agent scripts, and local scripts, but not for EntityScripts // 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();
Q_INVOKABLE void threadSafeAbortEvaluation();
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
bool isRunning() const { return _isRunning; } // used by ScriptWidget bool isRunning() const { return _isRunning; } // used by ScriptWidget