I have a Wall Class, and I store them in a list:
std::list<Wall> walls;
But when I add a wall like:
texture.loadFromFile("wall.png");
walls.push_back(Wall(texture, 500.f, 490.f, 4)); //arguments: texture, position X, postion Y, direction 4 = down
Then it's works, but the texture shown like it would be a nullptr. (So it's a white rectangle)
I draw it the walls this way:
for (Wall const &wal : walls)
wal.draw(window);
But if I add another wall to the list, then the first one is appear fine, but the second one is white, like:
And if I add different textured walls like:
texture.loadFromFile("wall.png");
walls.push_back(Wall(texture, 500.f, 490.f, 4));
walls.push_back(Wall(texture, 563.f, 490.f, 4));
walls.push_back(Wall(texture, 626.f, 490.f, 4));
walls.push_back(Wall(texture, 500.f, 600.f, 4));
walls.push_back(Wall(texture, 563.f, 600.f, 4));
walls.push_back(Wall(texture, 626.f, 600.f, 4));
texture.loadFromFile("wall2.png");
walls.push_back(Wall(texture, 720.f, 540.f, 0));
then 6. (the one before texture changes) will be corrupted:
I spend about 6 days of free time to figure out what could be the problem, and so far I managed to identify that the poblem is with my list, but I don't know what.
Because, if I create walls without adding to the a list, and draw them, then everything works, as intended.
(Of course I tried vectors , arrays, and so on, but I thing it would be reasonable to store them in a list)
The entire source code could be found at my GitHub: https://github.com/Kerachi/KerachiAny idea?