Skip to content

Commit 45da5f7

Browse files
authored
fix bug when disposing animation block (#11159)
1 parent cd88750 commit 45da5f7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

pxtblocks/fields/field_animation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ export class FieldAnimationEditor extends FieldAssetEditor<FieldAnimationOptions
235235

236236
onDispose() {
237237
super.onDispose();
238-
(this.sourceBlock_ as Blockly.BlockSvg).getSvgRoot().removeEventListener("mouseenter", this.onMouseEnter);
239-
(this.sourceBlock_ as Blockly.BlockSvg).getSvgRoot().removeEventListener("mouseleave", this.cancelAnimation);
238+
239+
const root = (this.sourceBlock_ as Blockly.BlockSvg)?.getSvgRoot();
240+
if (root) {
241+
root.removeEventListener("mouseenter", this.onMouseEnter);
242+
root.removeEventListener("mouseleave", this.cancelAnimation);
243+
}
240244
document.removeEventListener("mousemove", this.onDocumentMouseMove);
241245
}
242246
}

0 commit comments

Comments
 (0)