Skip to content

Commit 635e942

Browse files
committed
fix #256: Do not free registers of running scripts
1 parent 0263f7b commit 635e942

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/engine/virtualmachine.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,26 @@ void VirtualMachine::replaceReturnValue(const Value &v, unsigned int offset)
164164
/*! Continues running the script from last position (the first instruction is skipped). */
165165
void VirtualMachine::run()
166166
{
167+
impl->running = true;
168+
167169
unsigned int *ret = impl->run(impl->pos);
168170
assert(ret);
171+
169172
if (impl->savePos)
170173
impl->pos = ret;
174+
175+
impl->running = false;
171176
}
172177

173178
/*! Jumps back to the initial position. */
174179
void VirtualMachine::reset()
175180
{
176181
assert(impl->bytecode);
177182
impl->pos = impl->bytecode;
178-
impl->regCount = 0;
179183
impl->atEnd = false;
184+
185+
if (!impl->running) // Registers will be freed when the script stops running
186+
impl->regCount = 0;
180187
}
181188

182189
/*! Moves back to the last vm::OP_CHECKPOINT instruction in the bytecode. */

src/engine/virtualmachine_p.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct VirtualMachinePrivate
4343
Script *script = nullptr;
4444
unsigned int *pos = nullptr;
4545
unsigned int *checkpoint = nullptr;
46+
bool running = false;
4647
bool atEnd = false;
4748
std::vector<Loop> loops;
4849
std::vector<unsigned int *> callTree;

test/engine/engine_test.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,11 @@ TEST(EngineTest, NoCrashAfterStop)
521521
ASSERT_TRUE(p.load());
522522
p.run();
523523
}
524+
525+
TEST(EngineTest, NoCrashOnBroadcastSelfCall)
526+
{
527+
// Regtest for #256
528+
Project p("regtest_projects/256_broadcast_self_call_crash.sb3");
529+
ASSERT_TRUE(p.load());
530+
p.run();
531+
}
Binary file not shown.

0 commit comments

Comments
 (0)