From e0b314d3fb1ef1bf51bda966f76e2eb5828225bc Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 5 Dec 2018 15:02:27 -0500 Subject: [PATCH] Fix an issue where the targetId of a monitor could be reassigned This caused a local variable monitor to try running its thread on a different sprite, causing a new local variable to be created with the same monitor id. --- src/engine/blocks.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 8b8575b94..abda04f58 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -625,18 +625,22 @@ class Blocks { // Variable blocks may be sprite specific depending on the owner of the variable let isSpriteLocalVariable = false; if (block.opcode === 'data_variable') { - isSpriteLocalVariable = !optRuntime.getEditingTarget().isStage && - optRuntime.getEditingTarget().variables[block.fields.VARIABLE.id]; + isSpriteLocalVariable = !(optRuntime.getTargetForStage().variables[block.fields.VARIABLE.id]); } else if (block.opcode === 'data_listcontents') { - isSpriteLocalVariable = !optRuntime.getEditingTarget().isStage && - optRuntime.getEditingTarget().variables[block.fields.LIST.id]; + isSpriteLocalVariable = !(optRuntime.getTargetForStage().variables[block.fields.LIST.id]); } - const isSpriteSpecific = isSpriteLocalVariable || (optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) && optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific); - block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null; + if (isSpriteSpecific) { + // If creating a new sprite specific monitor, the only possible target is + // the current editing one b/c you cannot dynamically create monitors. + // Also, do not change the targetId if it has already been assigned + block.targetId = block.targetId || optRuntime.getEditingTarget().id; + } else { + block.targetId = null; + } if (wasMonitored && !block.isMonitored) { optRuntime.requestHideMonitor(block.id);