@@ -152,6 +152,7 @@ void Engine::start()
152152
153153 deleteClones ();
154154
155+ m_eventLoopMutex.lock ();
155156 m_timer->reset ();
156157 m_running = true ;
157158
@@ -160,6 +161,8 @@ void Engine::start()
160161 for (auto block : gfBlocks)
161162 startScript (block, target);
162163 }
164+
165+ m_eventLoopMutex.unlock ();
163166}
164167
165168void Engine::stop ()
@@ -360,6 +363,7 @@ void Engine::eventLoop(bool untilProjectStops)
360363 TargetScriptMap scripts = m_runningScripts; // this must be copied (for now)
361364
362365 do {
366+ m_eventLoopMutex.lock ();
363367 m_scriptsToRemove.clear ();
364368
365369 // Execute new scripts from last frame
@@ -376,12 +380,14 @@ void Engine::eventLoop(bool untilProjectStops)
376380 for (const auto &pair : m_runningScripts) {
377381 if (!pair.second .empty ()) {
378382 empty = false ;
383+ m_eventLoopMutex.unlock ();
379384 break ;
380385 }
381386 }
382387
383388 if (empty) {
384389 stop = true ;
390+ m_eventLoopMutex.unlock ();
385391 break ;
386392 }
387393 }
@@ -391,6 +397,7 @@ void Engine::eventLoop(bool untilProjectStops)
391397
392398 if (m_stopEventLoop) {
393399 stop = true ;
400+ m_eventLoopMutex.unlock ();
394401 break ;
395402 }
396403
@@ -400,6 +407,7 @@ void Engine::eventLoop(bool untilProjectStops)
400407 elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - frameStart);
401408 sleepTime = m_frameDuration - elapsedTime;
402409 timeout = sleepTime <= std::chrono::milliseconds::zero ();
410+ m_eventLoopMutex.unlock ();
403411 } while (!((m_redrawRequested && !m_turboModeEnabled) || timeout || stop));
404412
405413 if (stop)
@@ -1178,14 +1186,17 @@ BlockSectionContainer *Engine::blockSectionContainer(IBlockSection *section) con
11781186
11791187void Engine::finalize ()
11801188{
1189+ m_eventLoopMutex.lock ();
11811190 m_runningScripts.clear ();
11821191 m_scriptsToRemove.clear ();
11831192 m_running = false ;
11841193 m_redrawRequested = false ;
1194+ m_eventLoopMutex.unlock ();
11851195}
11861196
11871197void Engine::deleteClones ()
11881198{
1199+ m_eventLoopMutex.lock ();
11891200 removeExecutableClones ();
11901201 m_clones.clear ();
11911202
@@ -1201,6 +1212,8 @@ void Engine::deleteClones()
12011212 }
12021213 }
12031214 }
1215+
1216+ m_eventLoopMutex.unlock ();
12041217}
12051218
12061219void Engine::removeExecutableClones ()
0 commit comments