I am trying to create 1000 sf::Text objects. But loadFromFile returns 0 after 508 initialized objects. Why is that the case and is there a way to by pass this to create all 1000 objects? The code example demonstrates this.
Thank you for your time.
#include <iostream>
#include <SFML/Graphics.hpp>
class Text
{
private:
sf::Text text;
sf::Font font;
sf::RenderTarget& renderTarget;
public:
Text(const sf::String& fontPath, sf::RenderTarget& p_renderTarget) : renderTarget(p_renderTarget)
{
std::cout << "Font loaded: " << font.loadFromFile(fontPath) << std::endl;
text.setFont(font);
text.setString("Hallo Welt!");
text.setCharacterSize(25);
}
void Update() { renderTarget.draw(text); }
};
int main()
{
sf::RenderWindow window(sf::VideoMode(900, 600), "SFML works!");
std::vector<Text*> texts;
int textAmount = 1000;
for (int i = 0; i < textAmount; i++)
{
std::cout << "Nr." << i << ": ";
Text* t = new Text("arial.ttf", window);
texts.push_back(t);
}
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for (int i = 0; i < textAmount; i++)
{
texts[i]->Update();
}
window.display();
}
for (int i = 0; i < textAmount; i++)
{
delete texts[i];
}
}