Fix for empty substacks

This commit is contained in:
Tim Mickel 2016-05-03 13:45:22 -04:00
parent 47545e7109
commit 852b11519a
3 changed files with 26 additions and 7 deletions

View file

@ -64,7 +64,7 @@ Sequencer.prototype.stepThreads = function (threads) {
&& activeThread.nextBlock === null) {
activeThread.nextBlock = activeThread.stack.pop();
// Don't pop stack frame - we need the data.
// A new one won't be created when we execute.
// A new one won't be created when we execute.
}
if (activeThread.nextBlock === null) {
// No more on the stack
@ -96,6 +96,10 @@ Sequencer.prototype.stepThread = function (thread) {
// If the primitive would like to do control flow,
// it can overwrite nextBlock.
var currentBlock = thread.nextBlock;
if (!currentBlock) {
thread.status = Thread.STATUS_DONE;
return;
}
thread.nextBlock = this.runtime._getNextBlock(currentBlock);
var opcode = this.runtime._getOpcode(currentBlock);
@ -144,7 +148,12 @@ Sequencer.prototype.stepThread = function (thread) {
*/
var threadStartSubstack = function () {
// Set nextBlock to the start of the substack
thread.nextBlock = instance.runtime._getSubstack(currentBlock).value;
var substack = instance.runtime._getSubstack(currentBlock);
if (substack && substack.value) {
thread.nextBlock = substack.value;
} else {
thread.nextBlock = null;
}
instance.runtime.glowBlock(currentBlock, false);
switchedStack = true;
};

14
vm.js
View file

@ -1628,7 +1628,7 @@
&& activeThread.nextBlock === null) {
activeThread.nextBlock = activeThread.stack.pop();
// Don't pop stack frame - we need the data.
// A new one won't be created when we execute.
// A new one won't be created when we execute.
}
if (activeThread.nextBlock === null) {
// No more on the stack
@ -1660,6 +1660,10 @@
// If the primitive would like to do control flow,
// it can overwrite nextBlock.
var currentBlock = thread.nextBlock;
if (!currentBlock) {
thread.status = Thread.STATUS_DONE;
return;
}
thread.nextBlock = this.runtime._getNextBlock(currentBlock);
var opcode = this.runtime._getOpcode(currentBlock);
@ -1708,7 +1712,12 @@
*/
var threadStartSubstack = function () {
// Set nextBlock to the start of the substack
thread.nextBlock = instance.runtime._getSubstack(currentBlock).value;
var substack = instance.runtime._getSubstack(currentBlock);
if (substack && substack.value) {
thread.nextBlock = substack.value;
} else {
thread.nextBlock = null;
}
instance.runtime.glowBlock(currentBlock, false);
switchedStack = true;
};
@ -1980,6 +1989,7 @@
};
Scratch3Blocks.prototype.repeat = function(argValues, util) {
console.log('Running: control_repeat');
// Initialize loop
if (util.stackFrame.loopCounter === undefined) {
util.stackFrame.loopCounter = 4; // @todo arg

6
vm.min.js vendored

File diff suppressed because one or more lines are too long