Merge pull request #15818 from sabrina-shanman/crash_scriptengine_thread

(BUGZ-619) Fix potential crash when ending script on main thread
This commit is contained in:
Shannon Romano 2019-06-21 15:08:42 -07:00 committed by GitHub
commit 13615eb9ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -397,15 +397,20 @@ void ScriptEngine::executeOnScriptThread(std::function<void()> function, const Q
}
void ScriptEngine::waitTillDoneRunning() {
// Engine should be stopped already, but be defensive
stop();
auto workerThread = thread();
if (workerThread == QThread::currentThread()) {
qCWarning(scriptengine) << "ScriptEngine::waitTillDoneRunning called, but the script is on the same thread:" << getFilename();
return;
}
if (_isThreaded && workerThread) {
// We should never be waiting (blocking) on our own thread
assert(workerThread != QThread::currentThread());
// Engine should be stopped already, but be defensive
stop();
auto startedWaiting = usecTimestampNow();
while (workerThread->isRunning()) {
// If the final evaluation takes too long, then tell the script engine to stop running