From cfd6a5ef67474d7060928eabd19a2a220a810b42 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 1 Oct 2019 01:46:13 -0500 Subject: [PATCH] fix: children splicing --- packages/entity/traits/spawner.trait.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/entity/traits/spawner.trait.js b/packages/entity/traits/spawner.trait.js index f5bdbb0..fc32cef 100644 --- a/packages/entity/traits/spawner.trait.js +++ b/packages/entity/traits/spawner.trait.js @@ -70,8 +70,10 @@ export class Spawner extends decorate(Trait) { return { killAllChildren: () => { - for (let i = 0; i < this.children.length; i++) { - this.children[i].destroyGently(); + // Juggle children since this may cause splices and mess up the array. + const children = this.children.slice(0); + for (let i = 0; i < children.length; i++) { + children[i].destroyGently(); } },