Hey people!
I'm trying to understand why I keep getting an access violation while drawing a sf::Text.
I've managed to replicate my current scenario in the code below.
Basically, in that for loop, the pointers of the font present in a.text (m_library...) are set correctly but after the first iteration if I go ahead and check objects[0].text, those pointers are reset to NULL.
Could you please explain to me this behavior?
Thanks a lot!
Note: please ignore the ugliness of this code as it's only meant for demonstration purposes
class myClass
{
public:
sf::Text text;
sf::Font font;
};
void main()
{
std::vector<myClass> objects;
sf::Font f;
f.loadFromFile("arial.ttf");
for (int i = 0; i < 10; i++)
{
myClass a;
a.font = f;
a.text.setFont(a.font);
objects.push_back(a);
}
sf::RenderWindow window(VideoMode(100, 100), "window");
while (window.isOpen())
{
window.clear();
for (myClass a : objects)
{
window.draw(a.text);
}
window.display();
}
}