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

Author Topic: Unhandled exception while using Text and Font inside a class  (Read 1840 times)

0 Members and 1 Guest are viewing this topic.

mentor

  • Newbie
  • *
  • Posts: 31
    • View Profile
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?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unhandled exception while using Text and Font inside a class
« Reply #1 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?
« Last Edit: June 08, 2014, 04:55:58 pm by Jesper Juhl »

mentor

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Unhandled exception while using Text and Font inside a class
« Reply #2 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unhandled exception while using Text and Font inside a class
« Reply #3 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.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Unhandled exception while using Text and Font inside a class
« Reply #4 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unhandled exception while using Text and Font inside a class
« Reply #5 on: June 08, 2014, 05:08:03 pm »
Whoops, missed the 2012 support. Thanks zsbzsb for the correction :)

mentor

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Unhandled exception while using Text and Font inside a class
« Reply #6 on: June 08, 2014, 05:22:55 pm »
I downloaded nightly build for Visual 2013 and now everything works. Thanks!

 

anything