Jump to content

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: https://github.com/pixijs/pixi.js/issues/3806 (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?

Link to comment
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 (textureGC.run())  , that way you wont lose texture that you didnt use for 2 minutes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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