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.
This commit is contained in:
Christopher Willis-Ford 2017-06-07 17:05:24 -07:00
parent d41997b58b
commit 454082b569
2 changed files with 14 additions and 0 deletions

View file

@ -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) {

View file

@ -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;