Skip to content

Commit f8ebc85

Browse files
committed
fix #186: Keep track of whether the project is running
1 parent cdbe8f7 commit f8ebc85

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/engine/internal/engine.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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()
169171
void 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()
180183
void Engine::stop()
181184
{
182185
m_runningScripts.clear();
186+
m_scriptsToRemove.clear();
187+
m_running = false;
183188
}
184189

185190
void 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

349356
bool Engine::broadcastRunning(unsigned int index, VirtualMachine *sourceScript)

src/engine/internal/engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Engine : public IEngine
108108
std::unique_ptr<ITimer> m_defaultTimer;
109109
ITimer *m_timer = nullptr;
110110

111+
bool m_running = false;
111112
bool m_breakFrame = false;
112113
bool m_skipFrame = false;
113114
bool m_lockFrame = false;

0 commit comments

Comments
 (0)