Given the bug found with the old approach, fix this by going and deleting all of the monitor blocks for each sprite and the global variables.

This commit is contained in:
picklesrus 2018-12-06 18:59:58 -05:00
parent 694af40964
commit 3f3c34b43a
3 changed files with 27 additions and 7 deletions

View file

@ -1541,13 +1541,18 @@ class Runtime extends EventEmitter {
return newThreads;
}
/**
* Dispose all targets. Return to clean state.
*/
dispose () {
this.stopAll();
// Deleting each target's variable's monitors.
this.targets.forEach(target => {
if (target.isOriginal) target.deleteMonitors();
});
this.targets.map(this.disposeTarget, this);
this.monitorBlocks = new Blocks(true);
this._monitorState = OrderedMap({});
// @todo clear out extensions? turboMode? etc.

View file

@ -336,6 +336,26 @@ class Target extends EventEmitter {
}
}
/**
* Remove this target's monitors from the runtime state and remove the
* target-specific monitored blocks (e.g. local variables, global variables for the stage, x-position).
* NOTE: This does not delete any of the stage monitors like backdrop name.
*/
deleteMonitors () {
this.runtime.requestRemoveMonitorByTargetId(this.id);
let targetSpecificMonitorBlockIds;
if (this.isStage) {
// This only deletes global variables and not other stage monitors like backdrop number.
targetSpecificMonitorBlockIds = Object.keys(this.variables);
} else {
targetSpecificMonitorBlockIds = Object.keys(this.runtime.monitorBlocks._blocks)
.filter(key => this.runtime.monitorBlocks._blocks[key].targetId === this.id);
}
for (const blockId of targetSpecificMonitorBlockIds) {
this.runtime.monitorBlocks.deleteBlock(blockId);
}
}
/**
* Create a clone of the variable with the given id from the dictionary of
* this target's variables.

View file

@ -936,12 +936,7 @@ class VirtualMachine extends EventEmitter {
const restoreSprite = () => spritePromise.then(spriteBuffer => this.addSprite(spriteBuffer));
// Remove monitors from the runtime state and remove the
// target-specific monitored blocks (e.g. local variables)
this.runtime.requestRemoveMonitorByTargetId(targetId);
const targetSpecificMonitorBlockIds = Object.keys(this.runtime.monitorBlocks._blocks)
.filter(key => this.runtime.monitorBlocks._blocks[key].targetId === targetId);
for (const blockId of targetSpecificMonitorBlockIds) {
this.runtime.monitorBlocks.deleteBlock(blockId);
}
target.deleteMonitors();
const currentEditingTarget = this.editingTarget;
for (let i = 0; i < sprite.clones.length; i++) {
const clone = sprite.clones[i];