Wavertron Posted September 2, 2014 Share Posted September 2, 2014 Howdy all Does the Phaser.Text.destroy() method actually work? I'm testing in v2.0.7, and I've found that by adding a just a single Phaser.Text object, if I then restart current State many times, the memory skyrockets. Yes, I'm using a shutdown method, and I'm calling destroy and setting the phaser text object to null. But no dice. If I test the same code without creating the Phaser.Text object, the restart is fine, no crazy memory usage. I created a small test game that shows to bug reliably on my PC, can be seen here: http://phasertext.parseapp.com/ Two options are available, you can start the Game State with or without a Phaser.Text object being created.The Game State then has a 5 second timer and will do a restart 10 times.Little bit of info in the Console Log. Testing in Firefox and checking its total memory usage:- Without Phaser.Text memory bounces between 350 to 450mb during the 10 restarts.- With Phaser.Text memory skyrockets to 2 gig after 10 restarts and never comes back down until the tab/window is closed. Once closed, GC eventually kicks in and the memory settles back down to 300mb.Before and after each test, I shutdown Firefox. During the test I only have the one tab open running the game. The Game State code is below.The creation of a Phaser.Text object is driven by the setting of boolean BasicGame.createText when the Game State is started from the MainMenu (MainMenu code not shown, can be seen in test app via debug).BasicGame.Game = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: this.game; // a reference to the currently running game this.add; // used to add sprites, text, groups, etc this.camera; // a reference to the game camera this.cache; // the game cache this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it) this.load; // for preloading assets this.math; // lots of useful common math operations this.sound; // the sound manager - add a sound, play one, set-up markers, etc this.stage; // the game stage this.time; // the clock this.tweens; // the tween manager this.world; // the game world this.particles; // the particle manager this.physics; // the physics manager this.rnd; // the repeatable random number generator // You can use any of these from any function within this State. // But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.};BasicGame.Game.prototype = { textStyle: null, phaserText: null, restartCounter: 0, create: function () { this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.updateBoundsCollisionGroup(); this.game.physics.p2.setBoundsToWorld(true, true, true, true, false); this.game.physics.p2.setImpactEvents(true); this.game.physics.p2.gravity.y = 500; this.add.sprite(0, 0, 'gamepage'); //create a bunch of P2 boxes to cause lots of collisions and put a bit of load on the game this.boxes = this.game.add.group(); for (var i = 0; i <= 20; i++) { var box = this.game.add.sprite(100, 100, 'box'); this.game.physics.p2.enable(box); this.boxes.add(box); } this.textStyle = { font: "24px Verdana", fill: "#000000", align: "center", stroke: "#000000", strokeThickness: "2" }; if (BasicGame.createText) { this.phaserText = this.game.add.text(100, 150, 'Phaser.Text', this.textStyle); } if (this.restartCounter < 10) { //do 10 timer based restarts this.game.time.events.add(Phaser.Timer.SECOND * 5, this.restartFromTimer, this); } else { console.log('*** All timer based restarts completed ***'); } }, update: function () { }, restartFromTimer: function() { this.restartCounter++; console.log("*** Timed restart number: " + this.restartCounter); this.restartGame(); }, quitGame: function (pointer) { this.state.start('MainMenu'); }, restartGame: function (pointer) { this.state.restart(); }, shutdown: function() { console.log("Shutdown"); this.textStyle = null; if (this.phaserText != null) { console.log("phaserText destroy"); this.phaserText.destroy(); this.phaserText = null; } this.boxes.removeAll(); }}; Link to comment Share on other sites More sharing options...
rich Posted September 2, 2014 Share Posted September 2, 2014 Open a github issue (with the above text in) and we'll look into it. Phaser.Text is closely linked with Pixi.Text, so we may need to fix in there first. Link to comment Share on other sites More sharing options...
Wavertron Posted September 3, 2014 Author Share Posted September 3, 2014 Issue #1162 opened. I'm really hoping this is the source of the memory issue. I'm close to finishing a game, and after adding some music the restart became fatal on a phone (PC fairs better). My shutdown method is now 258 lines long and I've ran out of things to destroy()...Argh... Ultimately the only thing that fixed the issue was when I removed all use of Phaser.Text objects from the game. So then I made this simplified test case just to better pinpoint the issue. Link to comment Share on other sites More sharing options...
salvo Posted September 3, 2014 Share Posted September 3, 2014 hi,I had same problems. in Phaser.Text.prototype.destroy() change this.texture.destroy();with this.texture.destroy(true); then this works : PIXI.Texture.prototype.destroy = function(destroyBase){ if (destroyBase) this.baseTexture.destroy(); this.valid = false;}; hope this helps. Link to comment Share on other sites More sharing options...
Wavertron Posted September 3, 2014 Author Share Posted September 3, 2014 Hey Salvo.I tried your fix in my test game, looks good. Memory didn't skyrocket and stayed steady throughout the 10 restarts. Edit: Just saw on the github issue Rich's comments pushing in a fix. I'll try that out tonight and report back in the github issue. Link to comment Share on other sites More sharing options...
Wavertron Posted September 4, 2014 Author Share Posted September 4, 2014 Thanks all Salvo's suggestion fixes the bug. This can be used by anyone right now on 2.0.7Rich has committed the same fix into DEV branch 2.1 if you want to make the jump now. Link to comment Share on other sites More sharing options...
Recommended Posts