Sign in to follow this  

Handling destroy of generated textures from canvas

Recommended Posts

I need to generate some textures on the fly, bassicaly when map is loaded I generate several dozens simple gradient textures.

I found here: (last comments) that this is possible to use just one helper canvas to do this but after reading some other sources I am a little confused how to handle destroy of this textures.
At the moment I have some helperCanvas with 2D context to generate my textures and then I do:

// This create texture from helper canvas as I understand
var texture1 = new PIXI.Texture(new PIXI.BaseTexture(helperCanvas));

// This one "save" texture in GPU memory if I understood correctly.

// Create new sprite from this texture
var sprite = new Sprite( texture1 );

I do this in loop to create all needed sprites but I am not sure what should I do when map is unloaded, when I don't need these textures.
Is any action needed or GC can handle this? Should I remove them manually from textureManager by some method or call destroy on sprite?

Share this post

Link to post
Share on other sites

GC handles that after 2-5 minutes, I dont remember exactly. Also GC unload can cause problems, you dont use something for 2 minutes, it gets removed, but loads wrong image from helperCanvas.

Alternatively, if you have a list of those textures, you can call "texture.baseTexture.dispose()" or "texture.baseTexture.destroy()" for each of them. In that case, you can switch GC off "renderer.textureGC.mode = PIXI.GC_MODES.MANUAL" and do it only on scene switch (  , that way you wont lose texture that you didnt use for 2 minutes.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.