Fog implemented with RenderTexture not working now

I have implemented frog of war with RenderTexure. It works sometime but sometime the frog is missing. I cannot figure why. Could anyone help me?

void GameRunLayer::refreshWarFog() {
const int Circle_Radius = 20;
removeChildByTag(kWarFogNodeTag);
auto explored_sprites = SpriteBatchNode::create("UI/ui_base_circle03.png");
explored_sprites->setBlendFunc({GL_ZERO, GL_ONE_MINUS_SRC_ALPHA});


for (Tower* tower : towersVector) {
    auto tower_visible_area = Sprite::create("UI/ui_base_circle03.png");
    auto world_space_position = tower->getParent()->convertToWorldSpace(tower->getPosition());
    tower_visible_area->setPosition(world_space_position);
    tower_visible_area->setScale(tower->atkRadius / Circle_Radius);
    explored_sprites->addChild(tower_visible_area);
}

auto render_texture = RenderTexture::create(Director::getInstance()->getVisibleSize().width, Director::getInstance()->getVisibleSize().height);
render_texture->beginWithClear(0, 0, 0, 0.8);
explored_sprites->cocos2d::Node::visit();
render_texture->end();

auto retsprite = Sprite::createWithTexture(render_texture->getSprite()->getTexture());
retsprite->setFlippedY(true);
retsprite->setPosition(Director::getInstance()->getVisibleSize().width*0.5, Director::getInstance()->getVisibleSize().height*0.5);
retsprite->setTag(kWarFogNodeTag);
addChild(retsprite, kWarFogZOrder);
setExploredArea(explored_sprites);

}

I found the frog is only missing in release build. debug build is ok everytime.

I fixed it by calling this method twice.

refreshWarFog();
refreshWarFog();


Sorry couldn’t help myself. It’s ‘fog’ of war, not ‘frog’ :smiley:

When do you call refreshWarFrog()? in an update?

Also I’d recommend creating the render texture outside this method once, generating and destroying textures frequently is expensive. Also you can use the RenderTexture as a sprite, there’s no need to create a new sprite.

Sorry for my poor English. I mean fog really. Is there a better way to implement fog? Can someone show me how? thank you in advance