Skip to content

Commit 34aff35

Browse files
committed
The Video game object used an anonymous bound function for both the 'ended' and 'playing' event listeners, meaning that they were never removed properly (thanks @ramalhovfc phaserjs#2303)
1 parent 6a50e18 commit 34aff35

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
271271

272272
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. Doing this then sets the key to be the `frame` argument (the frame is set to zero). This allows you to create sprites using `load.image` during development, and then change them to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' and swapping it to be the key of the atlas data.
273273
* BitmapText.cleanText is a new method that will scan the given text and either remove or replace all characters that are not present in the font data. It is called automatically by `BitmapText.updateText`.
274+
* ArcadePhysics.Body.onCeiling is a new complementary method to go with onFloor (thanks @yigitozdemir #1610)
274275

275276
### Updates
276277

@@ -299,6 +300,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
299300
* When loading audio or video from blob or data URIs, the local variable was replaced too soon, throwing errors in `getAudioURL` and `getVideoURL` (thanks @milkey-mouse @jackfreak #2236 #2234)
300301
* Tween.hasStarted parameter was set to `false` when the tween was created, but not set again when the tween was stopped or ends. If `Tween.start` is used more than once the `onStart` callback is called only the first time (thanks @javivi91 #2199)
301302
* During a WebGL context loss the Phaser Cache was referencing the wrong local object (thanks @allenevans #2285)
303+
* The Video game object used an anonymous bound function for both the 'ended' and 'playing' event listeners, meaning that they were never removed properly (thanks @ramalhovfc #2303)
302304

303305
### Pixi Updates
304306

src/gameobjects/Video.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ Phaser.Video = function (game, key, url) {
205205
*/
206206
this._autoplay = false;
207207

208+
/**
209+
* @property {function} _endCallback - The addEventListener ended function.
210+
* @private
211+
*/
212+
this._endCallback = null;
213+
214+
/**
215+
* @property {function} _playCallback - The addEventListener playing function.
216+
* @private
217+
*/
218+
this._playCallback = null;
219+
208220
if (key && this.game.cache.checkVideoKey(key))
209221
{
210222
var _video = this.game.cache.getVideo(key);
@@ -644,7 +656,9 @@ Phaser.Video.prototype = {
644656
this.game.onPause.add(this.setPause, this);
645657
this.game.onResume.add(this.setResume, this);
646658

647-
this.video.addEventListener('ended', this.complete.bind(this), true);
659+
this._endCallback = this.complete.bind(this);
660+
661+
this.video.addEventListener('ended', this._endCallback, true);
648662

649663
if (loop)
650664
{
@@ -674,7 +688,8 @@ Phaser.Video.prototype = {
674688
}
675689
else
676690
{
677-
this.video.addEventListener('playing', this.playHandler.bind(this), true);
691+
this._playCallback = this.playHandler.bind(this);
692+
this.video.addEventListener('playing', this._playCallback, true);
678693
}
679694
}
680695

@@ -695,7 +710,7 @@ Phaser.Video.prototype = {
695710
*/
696711
playHandler: function () {
697712

698-
this.video.removeEventListener('playing', this.playHandler.bind(this));
713+
this.video.removeEventListener('playing', this._playCallback, true);
699714

700715
this.updateTexture();
701716

@@ -754,8 +769,8 @@ Phaser.Video.prototype = {
754769
}
755770
else
756771
{
757-
this.video.removeEventListener('ended', this.complete.bind(this), true);
758-
this.video.removeEventListener('playing', this.playHandler.bind(this), true);
772+
this.video.removeEventListener('ended', this._endCallback, true);
773+
this.video.removeEventListener('playing', this._playCallback, true);
759774

760775
if (this.touchLocked)
761776
{

0 commit comments

Comments
 (0)