SFML community forums

Help => Graphics => Topic started by: garman on December 29, 2010, 03:06:35 pm

Title: Unable to load font from file
Post by: garman on December 29, 2010, 03:06:35 pm
At first, an error would pop up in the console window saying that the font file couldn't be found (with a run time error), but now I'm just getting run time errors:
Code: [Select]
Unhandled exception at 0x757b9617 in sfml-test.exe: Microsoft C++ exception: std::length_error at memory location 0x0031f3f0..

My code looks like this:
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
sf::Font MyFont;
MyFont.LoadFromFile("arial.ttf");
sf::RenderWindow App(sf::VideoMode(800,600,32), "test");
sf::Event Event;
sf::Shape box = sf::Shape::Rectangle(0, 0, 50, 50, sf::Color(100, 100, 100));
box.SetPosition(100,100);
while(App.IsOpened())
{
while(App.GetEvent(Event))
{
if(Event.Type == Event.Closed) App.Close();
}
App.Clear(sf::Color(100, 149, 237));
App.Draw(box);
App.Display();
}
return EXIT_SUCCESS;
}


How can I fix this?

EDIT: If I use if (!MyFont.Load...) return EXIT_SUCCESS;, the same thing. I'm not sure what's going wrong. I put arial.ttf in the same directory as the executable, the libraries, etc... I even put it in the resource folder in the project and it doesn't work.
Title: Unable to load font from file
Post by: Laurent on December 29, 2010, 03:52:38 pm
What compiler do you use? Is "arial.ttf" in the same directory as your executable?
Title: Unable to load font from file
Post by: garman on December 29, 2010, 03:54:08 pm
I'm using VS2010. arial.ttf is in the same directory as my executable.
Title: Unable to load font from file
Post by: Laurent on December 29, 2010, 04:01:17 pm
Have you recompiled SFML?
Title: Unable to load font from file
Post by: garman on December 29, 2010, 04:32:53 pm
This is such a hassle. I'm trying to rebuild it but it keeps saying that it can't find the audio library.
Title: Unable to load font from file
Post by: Laurent on December 29, 2010, 05:01:11 pm
Can you be more specific please? What is the exact error?
Title: Unable to load font from file
Post by: garman on December 29, 2010, 05:56:28 pm
Code: [Select]
Unable to start program '...sfml-audio.lib'
The system cannot find the file specified.


I removed the full location, but it might be faulty because in the vc2008 folder, the next folders in the path are .. and .. (so it's ...vc2008\..\..\Temp\vc2008\sfml-audio\Debug DLL\sfml-audio.lib). AFAIK, there isn't a .. folder in the vc2008 folder...
Title: Unable to load font from file
Post by: Laurent on December 29, 2010, 07:16:35 pm
Why does it want to "start" the library? Where did you put "sfml-audio.lib"?