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

Author Topic: Stack around the variable "MyFont" was corrupted.  (Read 4675 times)

0 Members and 1 Guest are viewing this topic.

scyth3s

  • Newbie
  • *
  • Posts: 20
    • View Profile
Stack around the variable "MyFont" was corrupted.
« on: May 18, 2011, 04:58:40 pm »
I have this code, which, for test purposes, I copied and pasted directly from the 1.6 tutorial.

Code: [Select]

     sf::Font MyFont = sf::Font::GetDefaultFont();

// Create a graphical string
    sf::String Hello;
    Hello.SetText("Hello !\nHow are you ?");
    Hello.SetFont(MyFont);
    Hello.SetColor(sf::Color(0, 128, 128));
    Hello.SetPosition(100.f, 100.f);
    Hello.SetRotation(15.f);
    Hello.SetSize(50.f);


And I get the runtime error in the title bar. I've tried having SFML load Xirod font, which I put in the project folder (VS 2010) and the executable folder. No dice.
"My church is not full of..."

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Stack around the variable "MyFont" was corrupted.
« Reply #1 on: May 19, 2011, 02:48:02 am »
Do NOT use the default font. Last I checked, it's completely broken and results in errors. It might just be a specific version of SFML, though.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Stack around the variable "MyFont" was corrupted.
« Reply #2 on: May 19, 2011, 07:37:23 am »
The default font should work fine. But maybe it's the copy that is broken, try to get a reference on the default font instead of copying it.
Laurent Gomila - SFML developer

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Stack around the variable "MyFont" was corrupted.
« Reply #3 on: May 19, 2011, 08:40:34 am »
Quote from: "OniLink10"
Do NOT use the default font. Last I checked, it's completely broken and results in errors. It might just be a specific version of SFML, though.
That's odd. Isn't it just a copy of the Arial font? Should I always provide a font file instead? Sorry for the thread-hijacking, just curious.

scyth3s

  • Newbie
  • *
  • Posts: 20
    • View Profile
Stack around the variable "MyFont" was corrupted.
« Reply #4 on: May 19, 2011, 07:19:32 pm »
Quote from: "OniLink10"
Do NOT use the default font. Last I checked, it's completely broken and results in errors. It might just be a specific version of SFML, though.


I also tried loading Xirod TTF. Is there a specific spot on my hard drive it must be in?

Quote

maybe it's the copy that is broken, try to get a reference on the default font instead of copying it


As in sf::Font &MyFont = sf::Font::GetDefaultFont(); ?

I have tried both of these, and neither lent any dice. Linking with the debug libraries has yielded nothing as well.

Some more code snippets:
Code: [Select]
GButton.h
/////////////////////
/// The font that the button class will use
/////////////////////
const sf::Font *font;


Code: [Select]
GButton.cpp
GButton::GButton(sf::RenderWindow& window, std::string text, sf::Color selectedColor, sf::Color deselectedColor)
{
//set the render window
this->window = &window;

//set the colors
this->selectedColor = selectedColor;
this->deselectedColor = deselectedColor;

//reference to the default font
font = &sf::Font::GetDefaultFont();
this->text = sf::String(text, *font, 30);
}


Code: [Select]
GButton.cpp
void GButton::Draw()
{
window->Draw(text);
}


I couldn't get a module level const variable reference to compile, so I tried a pointer. Still the same runtime error. However, I did notice that no matter what I do, the font for the sf::String 'text' seems to have an invalid size

[/img]
"My church is not full of..."

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Stack around the variable "MyFont" was corrupted.
« Reply #5 on: May 19, 2011, 08:18:56 pm »
Would a minimal example (just a window, the font and a text) still reproduce the error? If so, copy it there and I'll test it.
Laurent Gomila - SFML developer

scyth3s

  • Newbie
  • *
  • Posts: 20
    • View Profile
Stack around the variable "MyFont" was corrupted.
« Reply #6 on: May 19, 2011, 10:06:31 pm »
I did some digging, and apparently, SFML was/is buggy with VS2010? I compiled my project in VS2008 and it worked all fine and dandy.
"My church is not full of..."

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Stack around the variable "MyFont" was corrupted.
« Reply #7 on: May 19, 2011, 10:36:13 pm »
The VC2008 libs are not compatible with VC2010, you must recompile SFML to use it with VC2010.
Laurent Gomila - SFML developer

scyth3s

  • Newbie
  • *
  • Posts: 20
    • View Profile
Stack around the variable "MyFont" was corrupted.
« Reply #8 on: May 20, 2011, 03:31:26 am »
AHA! This solved it. I never read about compiling it myself before! Interesting that it never caused me any issues until that text thing.
"My church is not full of..."

 

anything