@@ -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)
@@ -1173,14 +1181,17 @@ BlockSectionContainer *Engine::blockSectionContainer(IBlockSection *section) con
11731181
11741182void Engine::finalize ()
11751183{
1184+ m_eventLoopMutex.lock ();
11761185 m_runningScripts.clear ();
11771186 m_scriptsToRemove.clear ();
11781187 m_running = false ;
11791188 m_redrawRequested = false ;
1189+ m_eventLoopMutex.unlock ();
11801190}
11811191
11821192void Engine::deleteClones ()
11831193{
1194+ m_eventLoopMutex.lock ();
11841195 removeExecutableClones ();
11851196 m_clones.clear ();
11861197
@@ -1196,6 +1207,8 @@ void Engine::deleteClones()
11961207 }
11971208 }
11981209 }
1210+
1211+ m_eventLoopMutex.unlock ();
11991212}
12001213
12011214void Engine::removeExecutableClones ()
0 commit comments