How I remove a tile from layer

I have created .tmx file and rendered on screen. Layer having a particular tile that I want to remove from layer.

int i, j is cell row and column and 407 is id of Tile that I want to remove.

auto sprite = layer->getTileAt(Vec2(i, j));
if (sprite && layer->getTileGIDAt(Vec2(i, j)) == 407) { 
      sprite->removeFromParent();
}

It works on Window with Visual Studio, When I tried on Xcode then it give me

Assert failed: removeQuadAtIndex: Invalid index
Assertion failed: (index>=0 && index<_totalQuads), function removeQuadAtIndex, file /TechStuff/Cocos2d-x/MyCocos2d-x/cocos2d-x/cocos/renderer/CCTextureAtlas.cpp, line 414.

and app crashed.

Could you please provide a demo to test it?

You are removing the sprite itself which is being referenced by other tiles on layer.So remove the tile at a coord instead instead of the sprite.

Use tileLayerWalls->removeTileAt(Vec2(20,24)); to remove tile instead of the sprite;