This commit is contained in:
apple502j 2025-05-04 02:06:29 +00:00 committed by GitHub
commit 2d6e389385
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1055,10 +1055,13 @@ class VirtualMachine extends EventEmitter {
// target-specific monitored blocks (e.g. local variables)
target.deleteMonitors();
const currentEditingTarget = this.editingTarget;
for (let i = 0; i < sprite.clones.length; i++) {
const clone = sprite.clones[i];
this.runtime.stopForTarget(sprite.clones[i]);
this.runtime.disposeTarget(sprite.clones[i]);
const cloneCount = sprite.clones.length;
for (let i = 0; i < cloneCount; i++) {
// sprite.clones is shifted by sprite.removeClone called from runtime.disposeTarget,
// so it's safe to just handle the first element
const clone = sprite.clones[0];
this.runtime.stopForTarget(clone);
this.runtime.disposeTarget(clone);
// Ensure editing target is switched if we are deleting it.
if (clone === currentEditingTarget) {
const nextTargetIndex = Math.min(this.runtime.targets.length - 1, targetIndexBeforeDelete);