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

Author Topic: Problems with sf::Text  (Read 4640 times)

0 Members and 1 Guest are viewing this topic.

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Problems with sf::Text
« on: January 03, 2013, 05:25:36 pm »
Hi! I have some really annoying problem I cannot figure out how to mend.
When I compile & run the application I get this error:

"Unhandled exception at 0x5105551E (sfml-graphics-d-2.dll) in codeCounter.exe: 0xC0000005: Access violation reading location 0x00000004."

Here is my class:
Code: [Select]
class Draw
{
public:
Draw(sf::RenderWindow* rw);
~Draw();

void drawBox(int comments, int rows, int chars, int blanks, int tabs);

private:
sf::RenderWindow* m_Window;
sf::RectangleShape m_Box;
sf::Font m_Font;
sf::Text m_Text;
};

Code: [Select]
void Draw::drawBox(int comments, int rows, int chars, int blanks, int tabs)
{
m_Text.setPosition(200, 200);
m_Text.setCharacterSize(15);
m_Text.setColor(sf::Color::Black);

m_Window->draw(m_Text); // if I remove this, the application work, but I wouldn't have no text!
//....
}

If I have a break-point on the m_Text it say "No information available, no symbols from sfml-graphics-d-2.dll loaded".

Anyone that know how I can mend this annoying problem? ^^

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #1 on: January 03, 2013, 07:03:38 pm »
Does your text have a font?
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #2 on: January 04, 2013, 01:37:16 pm »
I have tried with a font loaded from file, but according to the documentation it isn't required.
I have tried both with and without a font set.

Sometimes I get the error that the variable 'text' or 'font' is corrupt but I have no clue why this is happening.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #3 on: January 04, 2013, 01:39:36 pm »
Quote
I have tried with a font loaded from file, but according to the documentation it isn't required.
If you use a more recent revision than 2.0 RC, the default font doesn't exist anymore.
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #4 on: January 04, 2013, 02:03:03 pm »
Oh, OK. Then the documentation is a bit misguiding!

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Text.php
"Note that you don't need to load a font to draw text, SFML comes with a built-in font that is implicitely used by default."

Anyway! I get the same error when I load a font. I even copied the font into the same folder as the code (and the debug folder).

Code: [Select]
Draw::Draw(sf::RenderWindow* rw) : m_Window(rw), m_Text("Hello World")
{
if (!m_Font.loadFromFile("arial.ttf"))
{
std::cout << std::endl << "Press Enter to shutdown..." << std::endl;
std::cin.ignore();
std::cin.get();
exit(0);
}
m_Text.setFont(m_Font); // fails here if I try to use setFont
m_Text.setPosition(200, 200);
m_Text.setCharacterSize(15);
m_Text.setColor(sf::Color::Black);
}

Code: [Select]
void Draw::drawBox(int comments, int rows, int chars, int blanks, int tabs)
{
m_Window->draw(m_Text); // fails at draw if I don't have setFont
// Code for drawing boxes below
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #5 on: January 04, 2013, 02:09:07 pm »
What's your compiler and OS? Did you recompile SFML yourself, or did you use a precompiled version?

Quote
Oh, OK. Then the documentation is a bit misguiding!
The online doc refers to the online release. If you want the doc that matches your own version of SFML, then build it when you build SFML.
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #6 on: January 04, 2013, 02:22:13 pm »
I use the pre-compiled version.
I use Visual Studio 2012 on a win7 machine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #7 on: January 04, 2013, 02:28:50 pm »
Quote
I use the pre-compiled version.
There's no official precompiled SFML 2.0 version for VS2012.
So... Which one is it? Where did you get it?
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #8 on: January 04, 2013, 02:39:05 pm »
http://www.sfml-dev.org/download.php
C++ | version 2.0 RC
For 2010

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #9 on: January 04, 2013, 02:48:20 pm »
Quote
For 2010
That's why it crashes.
And that's why the "getting started" tutorial for Visual C++ begins with:
Quote
You must download the package that matches your version of Visual C++. Indeed, a library compiled with Visual C++ 2008 won't be compatible with Visual C++ 2005 or 2011 for example. If there's no SFML package compiled for your version of Visual C++, you will have to recompile SFML.

And when I said "If you use a more recent revision than 2.0 RC", instead of replying "the documentation is misguiding" you should have said "no, that's the version I use"... :P
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #10 on: January 04, 2013, 02:58:30 pm »
I was hoping it would work when everything else works :)
I will be using VS2010 instead, I have it on my computer @ home ^^
I googled earlier and saw a similar problem about compiling for 2012 and you replied you didn't use it
so I guess it's easier to just setup SFML on 2010 instead and go from there ;P

Thanks for all the help! :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with sf::Text
« Reply #11 on: January 04, 2013, 03:02:51 pm »
SFML is not complicated to compile.

There are also unofficial nightly builds.

So... no, you're not forced to switch to an older compiler ;)
Laurent Gomila - SFML developer

Kim

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Problems with sf::Text
« Reply #12 on: January 04, 2013, 04:33:40 pm »
I only have a few days till this assignment is due, and this was the only thing still bugging me :p
So I'll try and set it up when our game-dev-assignment starts :)

 

anything