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) {
|
||||
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({
|
||||
id: e.blockId
|
||||
});
|
||||
|
|
|
@ -22,6 +22,13 @@ var execute = function (sequencer, thread) {
|
|||
var currentBlockId = thread.peekStack();
|
||||
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.
|
||||
var opcode = target.blocks.getOpcode(currentBlockId);
|
||||
var blockFunction = runtime.getOpcodeFunction(opcode);
|
||||
|
|
|
@ -383,9 +383,11 @@ Runtime.prototype._updateScriptGlows = function () {
|
|||
if (thread.requestScriptGlowInFrame && target == this._editingTarget) {
|
||||
var blockForThread = thread.peekStack() || thread.topBlock;
|
||||
var script = target.blocks.getTopLevelScript(blockForThread);
|
||||
if (script) {
|
||||
requestedGlowsThisFrame.push(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Compare to previous frame.
|
||||
for (var j = 0; j < this._scriptGlowsPreviousFrame.length; j++) {
|
||||
var previousFrameGlow = this._scriptGlowsPreviousFrame[j];
|
||||
|
@ -408,6 +410,19 @@ Runtime.prototype._updateScriptGlows = function () {
|
|||
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).
|
||||
* @param {?string} blockId ID for the block to update glow
|
||||
|
|
|
@ -173,6 +173,7 @@ Sequencer.prototype.proceedThread = function (thread) {
|
|||
Sequencer.prototype.retireThread = function (thread) {
|
||||
thread.stack = [];
|
||||
thread.stackFrame = [];
|
||||
thread.requestScriptGlowInFrame = false;
|
||||
thread.setStatus(Thread.STATUS_DONE);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue