Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser 2.1.1: Animated Tilesprite causing massive memory leak in game


jamaalsd
 Share

Recommended Posts

Hey all, I'm having trouble with Phaser 2.1.1 were an animated tilesprite is causing the game to crash through a memory leak of some kind.

 

details are as follows:

 

in preload:

/*The spritesheet is huge, especially for one item.  I am aware of this*/game.load.spritesheet('playerWaterTrail','media/img/sprites/player/waterTrail.png', 115, 160, 97);

in create:

 

/*create the sprite*/this.player.waterTrail = game.add.tileSprite(this.player.x+45, this.player.y-130, 115, 160, 'playerWaterTrail');/*add to the proper layer of the game*/this.baseLayer.add(this.player.waterTrail);/*create and add the animation*/this.player.waterTrail.animations.add('play',null,31,true);/*this causes a massive memory leak somehow over time*/this.player.waterTrail.animations.play('play');this.player.waterTrail.autoScroll(0,-this.WATER_TRAIL_SPEED);this.player.waterTrail.update = function (){    this.x = game.currentActiveState.player.x + 45;    this.y = game.currentActiveState.player.y - 130;}.bind(this.player.waterTrail);

Any thoughts on what is going on?  I'm having trouble tracking it down.

 
 
Link to comment
Share on other sites

this.player.waterTrail.update = function (){    this.x = game.currentActiveState.player.x + 45;    this.y = game.currentActiveState.player.y - 130;}.bind(this.player.waterTrail);

That bit looks suspicious to me - why are you using bind? This doesn't look typical of how you'd usually do it in Phaser. Could you try instead doing this in the game's main update function instead? Something like this:

update: function() {  this.player.waterTrail.position.copyFrom(game.currentActiveState.player.position);},
Link to comment
Share on other sites

Looks like everything is still the same.  The binding of update loops within objects has never been a problem.  I did that because of the way I structured the code.  Your way is better so I'll shift things over.  

 

To add to the mystery:  I forgot to mention that when Phaser is set to AUTO there is no memory leak but also the tileSprite fails to animate.  I had it set to CANVAS and this is when the problem occurs.

Link to comment
Share on other sites

Hmm. It's true that the way TileSprites work is much more suited to webGL (as you pretty much get it for free as a standard way of applying textures to quads) so maybe there is something weird going on in the canvas implementation. I'd perhaps put a test case together and post this as a possible issue on the pixi Github page, or mention it on the pixi forums? Phaser's TileSprite is just a simple wrapper for the functionality which is defined in pixi, so I'm pretty sure that's where the bug (if it is one) resides.

Link to comment
Share on other sites

  • 2 months later...

Anyone got any update on this?  I'm seeing similar issues where my game chews up to 2.5GB of memory in Chrome.  I've tried it a few times and same in all cases.  I just leave it idle overnight and it gets up to that amount of memory usage.  I am using a tilesprite, not sure if that is the one using it as I haven't had time to dig further yet.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...