Hello, I experience graphical glitch. I attached 2 screenshots, 1 with and 1 without graphical bug.
minimal code looks something like so
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
sf::Texture default_texture("my default texture.png");
struct Sprite
{
explicit Sprite() {}
explicit Sprite(const sf::Texture& _texture) : sprite_(_texture) {}
std::optional<sf::Sprite> sprite_ = std::nullopt;
};
Sprite first_sprite;
std::vector<Sprite> sprites;
void init()
{
first_sprite.sprite_->setTexture(default_texture);
for (int i =0; i < 5;++i)
{
sprites.push_back(first_sprite);
}
}
int main()
{
//init
sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML window");
init();
while (window.isOpen())
{
while (const std::optional event = window.pollEvent())
{
// Close window: exit
if (event->is<sf::Event::Closed>())
window.close();
}
window.clear();
for (int i =0; i < sprites.size(); ++i)
{
if (sprites.sprite_.has_value())
{
window.draw(sprites.sprite_.value());
}
}
window.display();
}
}
Whether or not the glitch appears I seem to be able to reliable reproduce based on the size of vector of sprites. (For examples I push_back 5 Sprites it appears, I do 7 it doesn't.
The wrapper for sf::Sprite is necessary I can't go around it.
OS: archlinux
Why is this happening? What might be the cause? I am at loss here, I seem to be lacking some knowledge. Might be because I copy the sprite, but I had no issue in the past.