SFML community forums

Help => Graphics => Topic started by: mentor on June 08, 2014, 04:39:05 pm

Title: Unhandled exception while using Text and Font inside a class
Post by: mentor on June 08, 2014, 04:39:05 pm
I have a class that has Text and Font variables:

Code: [Select]
using namespace sf;

class MyClass {
private:
   Font times;
   Text song_name;

public:
   MyClass();
   ~MyClass();
   void DrawMethod(RenderWindow&);
};

In constructor I load font, I set song_name font, song_name character size, color - that works fine. But when I try to use setString I get an unhandled exception error.

Code: [Select]
MyClass::MyClass() {
   times.loadFromFile("C:/Windows/Fonts/times.ttf");

   song_name.setFont(times);
   song_name.setCharacterSize(16);
   song_name.setColor(Color::White);
   song_name.setStyle(Text::Bold);

   //***Above works!***
   //But this doesn't:
   song_name.setString("and here's some text");
}

Same happens when I try to draw my text:

Code: [Select]
void MyClass::DrawMethod(RenderWindow& win) {
   win.draw(song_name);
}

What's happening?
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: Jesper Juhl on June 08, 2014, 04:52:05 pm
What SFML version exactly? Built from source or using official binary?
What compiler?
Have you tried using a debugger to track it down?
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: mentor on June 08, 2014, 05:00:37 pm
SFML 2.1, official binary. My IDE is Visual Studio 2013.

No, I haven't tried debugger. I'll give it a try.
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: Jesper Juhl on June 08, 2014, 05:02:56 pm
SFML 2.1, official binary. My IDE is Visual Studio 2013.

That won't work.
The official SFML 2.1 binaries are for VS2010.
Either switch to VS2010 or build SFML from source with/for VS2013. What you are doing at the moment won't ever work right.
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: zsbzsb on June 08, 2014, 05:06:40 pm
The official SFML 2.1 binaries are for VS2010.

The official binaries are for VS 2010 and 2012.

SFML 2.1, official binary. My IDE is Visual Studio 2013.

So you got 3 options, downgrade to VS 2012 (not recommended), build SFML yourself, or grab a nightly build here (http://www.nightlybuilds.ch).
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: Jesper Juhl on June 08, 2014, 05:08:03 pm
Whoops, missed the 2012 support. Thanks zsbzsb for the correction :)
Title: Re: Unhandled exception while using Text and Font inside a class
Post by: mentor on June 08, 2014, 05:22:55 pm
I downloaded nightly build for Visual 2013 and now everything works. Thanks!