mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Cleanly handle deleting running scripts (#162)
* Cleanly handle deleting running scripts * Turn off glow request on retire thread; add null check
This commit is contained in:
parent
9b4433069e
commit
8987330853
4 changed files with 28 additions and 1 deletions
|
@ -185,6 +185,10 @@ Blocks.prototype.blocklyListen = function (e, isFlyout, opt_runtime) {
|
||||||
if (this._blocks[e.blockId].shadow) {
|
if (this._blocks[e.blockId].shadow) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Inform any runtime to forget about glows on this script.
|
||||||
|
if (opt_runtime && this._blocks[e.blockId].topLevel) {
|
||||||
|
opt_runtime.quietGlow(e.blockId);
|
||||||
|
}
|
||||||
this.deleteBlock({
|
this.deleteBlock({
|
||||||
id: e.blockId
|
id: e.blockId
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,13 @@ var execute = function (sequencer, thread) {
|
||||||
var currentBlockId = thread.peekStack();
|
var currentBlockId = thread.peekStack();
|
||||||
var currentStackFrame = thread.peekStackFrame();
|
var currentStackFrame = thread.peekStackFrame();
|
||||||
|
|
||||||
|
// Verify that the block still exists.
|
||||||
|
if (!target ||
|
||||||
|
typeof target.blocks.getBlock(currentBlockId) === 'undefined') {
|
||||||
|
// No block found: stop the thread; script no longer exists.
|
||||||
|
sequencer.retireThread(thread);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Query info about the block.
|
// Query info about the block.
|
||||||
var opcode = target.blocks.getOpcode(currentBlockId);
|
var opcode = target.blocks.getOpcode(currentBlockId);
|
||||||
var blockFunction = runtime.getOpcodeFunction(opcode);
|
var blockFunction = runtime.getOpcodeFunction(opcode);
|
||||||
|
|
|
@ -383,7 +383,9 @@ Runtime.prototype._updateScriptGlows = function () {
|
||||||
if (thread.requestScriptGlowInFrame && target == this._editingTarget) {
|
if (thread.requestScriptGlowInFrame && target == this._editingTarget) {
|
||||||
var blockForThread = thread.peekStack() || thread.topBlock;
|
var blockForThread = thread.peekStack() || thread.topBlock;
|
||||||
var script = target.blocks.getTopLevelScript(blockForThread);
|
var script = target.blocks.getTopLevelScript(blockForThread);
|
||||||
requestedGlowsThisFrame.push(script);
|
if (script) {
|
||||||
|
requestedGlowsThisFrame.push(script);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Compare to previous frame.
|
// Compare to previous frame.
|
||||||
|
@ -408,6 +410,19 @@ Runtime.prototype._updateScriptGlows = function () {
|
||||||
this._scriptGlowsPreviousFrame = finalScriptGlows;
|
this._scriptGlowsPreviousFrame = finalScriptGlows;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Quiet" a script's glow: stop the VM from generating glow/unglow events
|
||||||
|
* about that script. Use when a script has just been deleted, but we may
|
||||||
|
* still be tracking glow data about it.
|
||||||
|
* @param {!string} scriptBlockId Id of top-level block in script to quiet.
|
||||||
|
*/
|
||||||
|
Runtime.prototype.quietGlow = function (scriptBlockId) {
|
||||||
|
var index = this._scriptGlowsPreviousFrame.indexOf(scriptBlockId);
|
||||||
|
if (index > -1) {
|
||||||
|
this._scriptGlowsPreviousFrame.splice(index, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit feedback for block glowing (used in the sequencer).
|
* Emit feedback for block glowing (used in the sequencer).
|
||||||
* @param {?string} blockId ID for the block to update glow
|
* @param {?string} blockId ID for the block to update glow
|
||||||
|
|
|
@ -173,6 +173,7 @@ Sequencer.prototype.proceedThread = function (thread) {
|
||||||
Sequencer.prototype.retireThread = function (thread) {
|
Sequencer.prototype.retireThread = function (thread) {
|
||||||
thread.stack = [];
|
thread.stack = [];
|
||||||
thread.stackFrame = [];
|
thread.stackFrame = [];
|
||||||
|
thread.requestScriptGlowInFrame = false;
|
||||||
thread.setStatus(Thread.STATUS_DONE);
|
thread.setStatus(Thread.STATUS_DONE);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue