From 4fafa2135a6c25a492fafad1d6698b4ee270153e Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 21 Jun 2019 09:32:00 -0700 Subject: [PATCH] Fix potential crash when ending script on main thread --- libraries/script-engine/src/ScriptEngine.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 9d29f32931..9ba8289b0c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -397,15 +397,20 @@ void ScriptEngine::executeOnScriptThread(std::function 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