Jump to content

[solved] Restarting/switching states repeatedly causes severe performance issues


iownall555
 Share

Recommended Posts

So I am having a bit of a performance issue with states. When restarting a state multiple times the game starts to show a noticeable slowdown which also slows down Chrome. This occurs with WebGL and Canvas.

 

For a bit of context here, I am messing around with a tile based RPG style game and I have created a method of choosing which map to display by passing a bunch of params (such as the map, tileset, tilemap layers etc) to the state start and restart commands. I had also planned on using states for various other tasks such as a battle system.

 

This init function for the state is here: (Though I'm not sure if it will help very much)

RPG.Gameplay = function (game){//A whole bunch of vars go here};RPG.Gameplay.prototype ={init: function (map, tilesets, bglayer, collsionlayer, objectlayer){if (map === null || tilesets === null || bglayer === null || collsionlayer === null || objectlayer === null || !this.cache.checkTilemapKey(map))this.game.destroy();current_map = map;current_bg = bglayer;current_coll = collsionlayer;current_obj = objectlayer;current_tilesets = tilesets;},//Other functions go here but I've intentionally left them out as they aren't relevant};

 

And is usually called with something like "this.state.restart("Gameplay", null, null, "mapname", {"Tiled tileset name" : "Phaser tileset key"}, "tile layer", "collisions layer", "objects");" as an example.

 

As I mentioned before, constant restarting causes major performance issues.

So what I'm wondering is, is this an issue with how the state system works (or possibly even tilesets)? Should I find a better method of displaying maps instead of using states multiple times?

 

Thanks.

Link to comment
Share on other sites

This look like a memory leak. 

 

Have you implemented shutdown method of the state you are restartin

 

I took your advice and stated destroying everything after the state is finished through the use of the shutdown method, the game switches states perfectly fine now without any lag. Either way I'm going to set it up to change maps w/o a state restart (so there's even less of a chance of a leak).

 

Thank you. Your answer is exactly what I needed to fix this.

Link to comment
Share on other sites

  • 7 months later...

I am running into the most bizarre problems after using game.state.start(game.state.current); or game.state.restart(true,true). The browser comes to a complete halt. Then when you restart the browser, the game doesn't load at all or the games runs but extremely slow (like 1FPS). Sometimes restarting the computer solves it, but I can't understand why calling game.state.start would cause this... it causes not just the current browser session to crash but all subsequent sessions .. why? I'm not calling it again in subsequent sessions, why shouldn't it load as it normally does? Has it something to do with Phaser's caching mechanisms as that's the only thing that could possibly carry over from one session to another? It just doesn't make any sense. 

 

This seems to be a Phaser problem as is happens on all browsers in canvas and webgl. But what internal phaser thing, other than cache, could possibly carry over from one session to another?

 

Have I mentioned this makes absolutely no sense? 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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