From c53a3308eedc2a634d3840b3c4b9fd0f0cada1ac Mon Sep 17 00:00:00 2001 From: cha0s Date: Fri, 3 May 2019 08:17:18 -0500 Subject: [PATCH] fix: unloop and avoid null traits from immediate destroy --- packages/entity/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/entity/index.js b/packages/entity/index.js index 49367f0..0bce52d 100644 --- a/packages/entity/index.js +++ b/packages/entity/index.js @@ -245,7 +245,7 @@ export class Entity extends decorate(Resource) { // Remove instance. delete this._traits[type]; // Unloop. - // instance.entity = undefined; + instance.entity = undefined; } removeTraits(types) { @@ -261,6 +261,11 @@ export class Entity extends decorate(Resource) { tick(elapsed) { for (const type in this._traits) { + // If .destroy is called immediately when ticking a trait, then the next + // traits could go away. + if (!(type in this._traits)) { + continue; + } const instance = this._traits[type]; instance.tick(elapsed); }