Griva Posted April 25, 2018 Share Posted April 25, 2018 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. renderer.textureManager.updateTexture(texture1.baseTexture); // 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? ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 25, 2018 Share Posted April 25, 2018 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. OSUblake and Griva 1 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 25, 2018 Share Posted April 25, 2018 Have a like for good question! Quote Link to comment Share on other sites More sharing options...
Griva Posted April 25, 2018 Author Share Posted April 25, 2018 Thank you very much, everything is clear now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.