Hello,
I've been going through some of the tutorials on SFML, and everything has been working until I got to text and fonts. When I try to run my program, I get the following error:
"Unhandled exception at 0x70e71f34 in fonttest.exe: 0xC0000005: Access violation reading location 0x00331000."
This is what my code looks like:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Text test");
sf::Font font;
if(!font.loadFromFile("arial.ttf"))
std::cout << "font not loaded" << std::endl;
sf::Text text("hello, world", font, 16);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
return 0;
}
I've tried putting my font file in the same folder as the executable and in the same folder as the source code, but I still get the same error.
The error occurs at the line if(!font.loadFromFile("arial.ttf"))
I'm using SFML 2.3.2 with Visual Studio 2010
Are you running it from the IDE or directly from the executable file because the if it's the executable file, the font would need to be in the folder as that instead.
As Gambit said, does the console output any information. Also, does it work without crashing if you don't load any font? You should also try just loading the font in an empty main to help narrow down the problem:
#include <SFML/Graphics.hpp>
int main()
{
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
std::cout << "Could not load font." << std::endl;
return EXIT_SUCCESS;
}
If your console is closing before you get a chance to see its output, consider delaying the program's closure before returning. This may be of some use (https://github.com/Hapaxia/Keep-Console-Open).
Try also using a full global path to check if the location is the problem.