From 454082b569e6cb1969ede222ba5fb771a4288e9c Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Wed, 7 Jun 2017 17:05:24 -0700 Subject: [PATCH] Improve cleanup on clone disposal The `dispose()` method on `RenderedTarget` now: - informs the runtime that it should end any threads corresponding the target being disposed, and - removes the clone from its sprite. --- src/sprites/rendered-target.js | 2 ++ src/sprites/sprite.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 0bc5cff6e..2fb0ddf9e 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -832,6 +832,8 @@ class RenderedTarget extends Target { */ dispose () { this.runtime.changeCloneCounter(-1); + this.runtime.stopForTarget(this); + this.sprite.removeClone(this); if (this.renderer && this.drawableID !== null) { this.renderer.destroyDrawable(this.drawableID); if (this.visible) { diff --git a/src/sprites/sprite.js b/src/sprites/sprite.js index 3a0402a16..293a1f265 100644 --- a/src/sprites/sprite.js +++ b/src/sprites/sprite.js @@ -58,6 +58,18 @@ class Sprite { } return newClone; } + + /** + * Disconnect a clone from this sprite. The clone is unmodified. + * In particular, the clone's dispose() method is not called. + * @param {!RenderedTarget} clone - the clone to be removed. + */ + removeClone (clone) { + const cloneIndex = this.clones.indexOf(clone); + if (cloneIndex >= 0) { + this.clones.splice(cloneIndex, 1); + } + } } module.exports = Sprite;