From bd1d64e89c74966db601c3951af68f7ce74a6672 Mon Sep 17 00:00:00 2001 From: Frank Weindel <6070611+frank-weindel@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:57:54 -0400 Subject: [PATCH] Fix: Destroy attached children when destroying a Node --- src/core/CoreNode.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/CoreNode.ts b/src/core/CoreNode.ts index 814a9ec7..9fb59430 100644 --- a/src/core/CoreNode.ts +++ b/src/core/CoreNode.ts @@ -1312,12 +1312,19 @@ export class CoreNode extends EventEmitter { this.props.texture = null; this.props.shader = this.stage.defShaderCtr; + const children = [...this.children]; + for (let i = 0; i < children.length; i++) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + children[i]!.destroy(); + } + // This very action will also remove the node from the parent's children array + this.parent = null; + if (this.rtt) { this.stage.renderer.removeRTTNode(this); } this.removeAllListeners(); - this.parent = null; } renderQuads(renderer: CoreRenderer): void {