File tree Expand file tree Collapse file tree 4 files changed +17
-1
lines changed Expand file tree Collapse file tree 4 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ void Engine::frame()
132132
133133 do {
134134 script->run ();
135- if (script->atEnd ()) {
135+ if (script->atEnd () && m_running ) {
136136 for (auto &[key, value] : m_runningBroadcastMap) {
137137 size_t index = 0 ;
138138
@@ -152,6 +152,8 @@ void Engine::frame()
152152 } while (!script->atEnd () && !m_breakFrame);
153153 }
154154
155+ assert (m_running || m_scriptsToRemove.empty ());
156+
155157 for (auto script : m_scriptsToRemove) {
156158 size_t index = -1 ;
157159 for (size_t i = 0 ; i < m_runningScripts.size (); i++) {
@@ -169,6 +171,7 @@ void Engine::frame()
169171void Engine::start ()
170172{
171173 m_timer->reset ();
174+ m_running = true ;
172175
173176 for (auto target : m_targets) {
174177 auto gfBlocks = target->greenFlagBlocks ();
@@ -180,6 +183,8 @@ void Engine::start()
180183void Engine::stop ()
181184{
182185 m_runningScripts.clear ();
186+ m_scriptsToRemove.clear ();
187+ m_running = false ;
183188}
184189
185190void Engine::startScript (std::shared_ptr<Block> topLevelBlock, std::shared_ptr<Target> target)
@@ -344,6 +349,8 @@ void Engine::run()
344349
345350 lastFrameTime = currentTime;
346351 }
352+
353+ stop ();
347354}
348355
349356double Engine::fps () const
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ class Engine : public IEngine
115115 double m_fps = 30 ; // default FPS
116116 std::chrono::milliseconds m_frameDuration; // will be computed in run()
117117
118+ bool m_running = false ;
118119 bool m_breakFrame = false ;
119120 bool m_skipFrame = false ;
120121 bool m_lockFrame = false ;
Original file line number Diff line number Diff line change @@ -407,3 +407,11 @@ TEST(EngineTest, Clones)
407407 ASSERT_EQ ((*list)[i].toString (), " 1 2" ); // TODO: Change this to "12" after #188 is fixed
408408 }
409409}
410+
411+ TEST (EngineTest, NoCrashAfterStop)
412+ {
413+ // Regtest for #186
414+ Project p (" regtest_projects/186_crash_after_stop.sb3" );
415+ ASSERT_TRUE (p.load ());
416+ p.run ();
417+ }
You can’t perform that action at this time.
0 commit comments