From b95350da6eb5cf75948e9a713db060f6df51300f Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Wed, 15 Aug 2018 14:31:40 -0400 Subject: [PATCH] Fix issue where deleting a sprite with a monitored local variable creates that local variable on all other sprites after switching sprites twice or more. --- src/virtual-machine.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 79513103f..ed9c340da 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -852,7 +852,14 @@ class VirtualMachine extends EventEmitter { } const spritePromise = this.exportSprite(targetId, 'uint8array'); 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); + } const currentEditingTarget = this.editingTarget; for (let i = 0; i < sprite.clones.length; i++) { const clone = sprite.clones[i];