History

Fix potential crash when ending script on main thread

sabrina-shanman committed 7 years ago

Commit 4fafa211 parent b23badf1 file · +9 −4Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+9−4
@@ -397,15 +397,20 @@ void ScriptEngine::executeOnScriptThread(std::function<void()> function, const Q · 396 unmodified lines
397397 }
398398
399399 void ScriptEngine::waitTillDoneRunning() {
400+ // Engine should be stopped already, but be defensive
401+ stop();
402+
400403 auto workerThread = thread();
401−
404+
405+ if (workerThread == QThread::currentThread()) {
406+ qCWarning(scriptengine) << "ScriptEngine::waitTillDoneRunning called, but the script is on the same thread:" << getFilename();
407+ return;
408+ }
409+
402410 if (_isThreaded && workerThread) {
403411 // We should never be waiting (blocking) on our own thread
404412 assert(workerThread != QThread::currentThread());
405413
406− // Engine should be stopped already, but be defensive
407− stop();
408−
409414 auto startedWaiting = usecTimestampNow();
410415 while (workerThread->isRunning()) {
411416 // If the final evaluation takes too long, then tell the script engine to stop running