mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-26 06:10:26 -04:00
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.
This commit is contained in:
parent
122443a75f
commit
e0b314d3fb
1 changed files with 10 additions and 6 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue