mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:09:24 +02:00
Fix potential crash when ending script on main thread
This commit is contained in:
parent
b23badf374
commit
4fafa2135a
1 changed files with 9 additions and 4 deletions
|
@ -397,15 +397,20 @@ void ScriptEngine::executeOnScriptThread(std::function<void()> function, const Q
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::waitTillDoneRunning() {
|
void ScriptEngine::waitTillDoneRunning() {
|
||||||
|
// Engine should be stopped already, but be defensive
|
||||||
|
stop();
|
||||||
|
|
||||||
auto workerThread = thread();
|
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) {
|
if (_isThreaded && workerThread) {
|
||||||
// We should never be waiting (blocking) on our own thread
|
// We should never be waiting (blocking) on our own thread
|
||||||
assert(workerThread != QThread::currentThread());
|
assert(workerThread != QThread::currentThread());
|
||||||
|
|
||||||
// Engine should be stopped already, but be defensive
|
|
||||||
stop();
|
|
||||||
|
|
||||||
auto startedWaiting = usecTimestampNow();
|
auto startedWaiting = usecTimestampNow();
|
||||||
while (workerThread->isRunning()) {
|
while (workerThread->isRunning()) {
|
||||||
// If the final evaluation takes too long, then tell the script engine to stop running
|
// If the final evaluation takes too long, then tell the script engine to stop running
|
||||||
|
|
Loading…
Reference in a new issue