Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unable to load font from file  (Read 5717 times)

0 Members and 1 Guest are viewing this topic.

garman

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unable to load font from file
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unable to load font from file
« Reply #1 on: December 29, 2010, 03:52:38 pm »
What compiler do you use? Is "arial.ttf" in the same directory as your executable?
Laurent Gomila - SFML developer

garman

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unable to load font from file
« Reply #2 on: December 29, 2010, 03:54:08 pm »
I'm using VS2010. arial.ttf is in the same directory as my executable.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unable to load font from file
« Reply #3 on: December 29, 2010, 04:01:17 pm »
Have you recompiled SFML?
Laurent Gomila - SFML developer

garman

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unable to load font from file
« Reply #4 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unable to load font from file
« Reply #5 on: December 29, 2010, 05:01:11 pm »
Can you be more specific please? What is the exact error?
Laurent Gomila - SFML developer

garman

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unable to load font from file
« Reply #6 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...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unable to load font from file
« Reply #7 on: December 29, 2010, 07:16:35 pm »
Why does it want to "start" the library? Where did you put "sfml-audio.lib"?
Laurent Gomila - SFML developer