Hi, I can’t solve this problem for a long time, can you help me please?
I’m trying to merge some textures into one and use it as a texture for the sprite.
The problem is that the retained sprites and rendertextures are never getting released with my implementation.
If I put release after visit() on sprites, nothing is getting drawn to RenderTexture somewhy. (may be it’s because it has not enough time to draw sprite into texture before releasing)
I call that function a lots of times so there are hundreds of unnecessary GL calls and GL verts (otherwise, when I created my sprites with just 1 png file there was like 500 gl verts and 2-5 gl calls)
I need to release that sprites and rendertextures, please help me
Here is how I’m trying to do that
Texture2D * mergeTextures(TexturesList * textures)
{
auto rt = RenderTexture::create(256, 256);
rt->retain(); //this never gets released
rt->begin();
int n = textures->parts.size();
for (int i = 0; i < n; ++i)
{
auto spr = Sprite::create(textures->parts[i]->getFilePath());
spr->setPosition(Vec2(spr->getContentSize().width / 2, spr->getContentSize().height)); //don't look at that yet
spr->retain(); //this never gets released
spr->visit();
//spr->release(); //when I do that, nothing is getting drawn to rt
}
rt->end();
auto tex = rt->getSprite()->getTexture();
//rt->release(); //then I do this, it's stopping to work too
return tex;
}