SFML community forums

Help => Graphics => Topic started by: Fox3 on June 13, 2010, 01:33:28 pm

Title: SetText crash
Post by: Fox3 on June 13, 2010, 01:33:28 pm
I have a problem with my code, it suddenly crashes when I SetText :(
Code: [Select]
textbutton okbutton(24, 24, 64, 32);
okbutton.settext("OK", resmgr.fonts["tuffy"]);

Code: [Select]
struct textbutton : button
{
    sf::String text;
    void settext(std::string newtext, sf::Font newfont);
    void drawtext(sf::RenderWindow *app);
    textbutton() : button::button(){};
    textbutton(int nx, int ny, int nw, int nh) : button::button(nx, ny, nw, nh){};
};
void textbutton::settext(std::string newtext, sf::Font newfont)
{
    text.SetFont(newfont);
    text.SetSize(12);
--->text.SetText(newtext);
}
Title: SetText crash
Post by: Fox3 on June 13, 2010, 06:21:03 pm
Some facts:
Its a SIGTRAP from ntdll :(
text is shown as incomplete type.
Title: SetText crash
Post by: Laurent on June 13, 2010, 06:34:13 pm
You must pass your sf::Font by reference, otherwise it is copied locally to the function, and your string uses this local copy which is detroyed after the function ends.
Title: SetText crash
Post by: Fox3 on June 13, 2010, 06:36:58 pm
OMG!!! IT WORKS NOW!!! :D
Many thanks to Laurent ^^