SFML community forums

Help => Graphics => Topic started by: scyth3s on May 18, 2011, 04:58:40 pm

Title: Stack around the variable "MyFont" was corrupted.
Post by: scyth3s 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: OniLinkPlus 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: Laurent 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: Contadotempo 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: scyth3s 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

(http://i128.photobucket.com/albums/p187/LaKrakken/relaventerror.png)[/img]
Title: Stack around the variable "MyFont" was corrupted.
Post by: Laurent 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: scyth3s 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: Laurent 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.
Title: Stack around the variable "MyFont" was corrupted.
Post by: scyth3s 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.