MrBill

Members
  • Content Count

    7
  • Joined

  • Last visited

About MrBill

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Got fontfaceobserver to work pretty easily. Appreciate the help.
  2. Working on a minimal gui layer for my project. Text displays fine currently, but I was wondering how to load a custom font for PIXI.Text / PIXI.TextStyle? I looked around and saw webfont loader (link) being recommended for this problem. This looks fine, and I'm willing to use it if it's too inconvenient otherwise, but I was wondering if there was an alternative (more manual) way of doing this? I was thinking of having the fonts stored on the website locally, or retrieve them before the game starts using google fonts. The loader seems somewhat overkill for what I want and I've made it a minor challenge to use as much vanilla javaScript as possible for the project. Appreciate any input.
  3. Looks like I fixed it by doing .destroy(true) for PIXI.Text and PIXI.Graphics objects and clearing the Texture cache with PIXI.utils.clearTextureCache(). I really appreciate all the responses I got! Thank you! EDIT: Though I wonder if there's a good way to only remove certain textures. EDIT 2: I think I understand now. Here's what my code looks like. Currently I only remove the generic pixiid textures being cached that are leading to a memory leak. Good thing the API documentation has links to the source code! TextureManager.prototype.clearTextureCache = function(clearAll=false){ let generic = "pixiid"; if(clearAll === true){ PIXI.utils.clearTextureCache(); } else { let cache = PIXI.utils.TextureCache; Object.keys(cache).forEach(key => { if(key.startsWith(generic) === true){this.removeFromTextureCache(key)}; }); cache = PIXI.utils.BaseTextureCache; Object.keys(cache).forEach(key => { if(key.startsWith(generic) === true){this.removeFromTextureCache(key, cache)}; }); }; };
  4. Can't figure out how to deal with memory leaks for the (I believe, but not 100% certain) PIXI.Text and PIXI.Graphics objects. Currently I create and .destroy() these every frame but it's still being referenced somewhere and I don't know where. I think it's the PIXI.Text objects mainly because Firefox's memory snapshots in Tree Map show the Canvas continuously increasing in memory size. Do PIXI.Graphics also use the canvas? I created this function that will call whenever I want to remove a reference from the Cache. I only call this for objects with generic ids like "pixiid_7". I get the ids from the PIXI.Text.canvas._pixiid TextureManager.prototype.removeFromTextureCache = function(id){ let cache = PIXI.utils.TextureCache; if(cache[id]){ delete cache[id]; } else console.error(`Error while trying to delete from TextureCache: ${id} does not exist as a property.`); }; I'm not sure if this works at the moment because I still can't correctly pinpoint which objects are added to TextureCache and which are not (the error message fires off). Additionally, TextureCache doesn't have any documentation to work with. My destroy function currently looks like this: TextureManager.prototype.destroyObject = function(object){ switch(object.constructor){ case PIXI.Text: let cachedId = object.canvas._pixiId; object.destroy(); this.removeFromTextureCache(cachedId); break; default: object.destroy(); }; }; Basically I need help figuring out how to remove all traces of the different types of objects. I want to rework my game framework to reuse text like how I did for sprites. But without knowing how to properly delete them memory leaks are inevitable.
  5. To anyone having similar issues, I've cut down significantly on memory leaking by reusing sprites & textures for persistent entities like the player, and storing all disposable pixi graphics objects (like sprites for individual tiles to be drawn) in a pool (represented as a JavaScript Set object). Every frame the disposable objects are destroyed and the pool is cleared. I also implemented view culling for the tiles. I will probably look into combining all the tiles textures into a single texture next to keep the size of the pool low to lower the amount of iterations each frame.
  6. Could you elaborate on this? Not too well versed with the graphics back-end so I'm attempting my proposed solution first. I set it to call destroy() on every object that is drawn in a single frame. Renderer.prototype.addToGarbage = function(object){ this.garbage.push(object); }; Renderer.prototype.garbageCollect = function(){ this.garbage.forEach(e => e.destroy()); this.garbage = []; }; Renderer.prototype.draw = function(child){ this.addToGarbage(child); this.app.stage.addChild(child); }; Renderer.prototype.clear = function(){ this.app.stage.removeChildren(); this.garbageCollect(); }; Where this.garbage is an array that contains all the objects being drawn. It kinda works. There's some decrease in the amount of memory being leaked but it's still leaking. By snooping around the Firefox developer settings I was able to find that indeed the PIXI.Text constructor is partly responsible. You mentioned something about canvases? How can I account for those?
  7. I couldn't seem to find a clear solution online that would apply to me anywhere but if this has been discussed elsewhere feel free to link me there. My game's fps dips after running for only a few minutes. Shortly after my os slows down because my game uses up all the memory of the browser. I suspect the culprit is how I currently draw sprites because my "game" currently only involves placing a few sprites/text on the screen. I have my custom game framework setup to only really use Pixi.js primitives like PIXI.Texture, PIXI.Sprite, PIXI.Text, etc. My Spritesheet class currently contains a single texture attribute that refers to the texture of the entire spritesheet. When it's time to take a single sprite from the Spritesheet, the Spritesheet object creates a copy of its texture attribute and creates a new PIXI.Sprite object using that copy. I create a copy of the texture because changing rect of the Spritesheet's texture attribute would affect all sprites that use that Spritesheet. Drawing involves only adding the PIXI.Sprite object to the stage and clearing just removes all children from the app stage (I don't currently use containers). Here's the method that creates a sprite from the Spritesheet: SpriteSheet.prototype.getSprite = function(index_X, index_Y){ let rect = this._getRectFromIndex(index_X, index_Y); let texture = new PIXI.Texture(this.texture); texture.frame = rect; return new PIXI.Sprite(texture); }; this._getRectFromIndex is just an internal calculation that returns the PIXI.Rectangle object for the frame Here's the draw method: Renderer.prototype.draw = function(child){ this.app.stage.addChild(child); }; And here's the clear method: Renderer.prototype.clear = function(){ this.app.stage.removeChildren(); }; I'm pretty sure creating new Textures/Sprites every frame and only clearing the stage is the cause so I'm wondering what's the best way to improve performance with what I've given. Would just iterating and destroying these textures in clear every frame suffice?