ImageComponent doesnt render anything


#1
class Tile : public ImageComponent
{
public:
	Tile(std::string id, const Image& image)
		: ImageComponent(id)
	{
		setImage(image);
	}
};


class Tab : public Component
{
        Tab()
        {  
             int size; 
             // process size
	         for (int a = 0; a < size; a++)
	         {
	             nodes.add(&getDefaultTile());
                 addAndMakeVisible(*nodes[a]);
	        }
        }

        static Tile& getDefaultTile()
	    {
	          static Tile defaultTile("-1", getImageFromFile("Asset/defaultNodeImage.png")); 
              ///////// getImageFromFile() simply loads image from file and return it.
	          return defaultTile;
	    }

        OwnedArray<Tile> nodes; 
}

this code doesnt render anything. but when i make this to add node

	         for (int a = 0; a < size; a++)
	         {
	             nodes.add(new Tile("-1", getImageFromFile("Asset/defaultNodeImage.png")); 
                 addAndMakeVisible(*nodes[a]);
	        }

it works but i really need to make the first snippet work so i wont need to allocate bunch of Tile that has the same state.

any help is appreciated thanks.


#2

Solved now. It’s actually working. I actually created 2 Tab objects and im too stupid not looking at the 2nd tab.

so what happened is when i create the 2nd tab object this line
addAndMakeVisible(*nodes[a]);
adds the static tile it and after that the tile will be removed at the first tab.