Hi,
So I'm trying to get started on a new game. I figured that I could streamline the action of rendering text by putting all of the routines needed to do it (setting the font, the size, the color, and the text itself) into a function but when I try to execute this function, I get the error "Exception thrown at 0x0FD2485F (sfml-graphics-d-2.dll) in SFMLProject.exe: 0xC0000005: Access violation reading location 0x3F800004."
Here is my code:
#include <SFML/Graphics.hpp>
sf::Text drawText(sf::Font font, std::string inputText, int size, sf::Color color) //Function to draw text (TODO: Add the ability to specify coordinates)
{
sf::Text outputText;
outputText.setFont(font);
outputText.setString(inputText);
outputText.setCharacterSize(size);
outputText.setFillColor(color);
return outputText;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Project");
sf::CircleShape shape(100.f);
sf::Font testFont;
testFont.loadFromFile("calibri.ttf");
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.draw(drawText(testFont, "Development Build 0", 12, sf::Color::White));
window.display();
}
return 0;
}
EDIT: I just want to add that this does not happen when I manually draw text in the main function.