Skip to content

Commit d264d7e

Browse files
authored
Merge pull request #200 from scratchcpp/non_atomic_warp
Fix #146: Fix wait blocks being ignored in "warp" scripts
2 parents 26edb40 + dce4c6f commit d264d7e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/engine/virtualmachine.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,14 @@ void VirtualMachine::moveToLastCheckpoint()
190190
* \param[in] savePos Changes the return value of savePos().
191191
* \param[in] breakAtomic Whether to break the frame after stopping the script.
192192
* \param[in] goBack Whether to go back so that the current instruction can run again in the future.
193-
* \note Nothing will happen if the script is set to run without screen refresh.
193+
* \note If the script is set to run without screen refresh, the VM won't stop.
194+
* The only parameter which won't be ignored is goBack.
194195
*/
195196
void VirtualMachine::stop(bool savePos, bool breakAtomic, bool goBack)
196197
{
197-
if (impl->warp)
198-
return;
199198
impl->stop = true;
200-
impl->savePos = savePos;
201-
impl->atomic = !breakAtomic;
199+
impl->savePos = savePos && !impl->warp;
200+
impl->atomic = !breakAtomic || impl->warp;
202201
impl->goBack = goBack;
203202
}
204203

src/engine/virtualmachine_p.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
201201
atEnd = true;
202202
return pos;
203203
} else {
204+
if (callTree.size() == 1)
205+
warp = false;
206+
204207
pos = callTree.back();
205208
callTree.pop_back();
206209
procedureArgTree.pop_back();
@@ -689,7 +692,11 @@ do_exec : {
689692
// This is for example used in the wait block (to call it again with the same time value).
690693
} else
691694
FREE_REGS(ret);
692-
return pos;
695+
696+
if (!warp) // TODO: This should always return if there's a "warp timer" enabled
697+
return pos;
698+
699+
DISPATCH(); // this avoids freeing registers after "stopping" a warp script
693700
}
694701
FREE_REGS(ret);
695702
DISPATCH();

0 commit comments

Comments
 (0)