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

Author Topic: SetText crash  (Read 3490 times)

0 Members and 1 Guest are viewing this topic.

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
SetText crash
« 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);
}

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
SetText crash
« Reply #1 on: June 13, 2010, 06:21:03 pm »
Some facts:
Its a SIGTRAP from ntdll :(
text is shown as incomplete type.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetText crash
« Reply #2 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.
Laurent Gomila - SFML developer

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
SetText crash
« Reply #3 on: June 13, 2010, 06:36:58 pm »
OMG!!! IT WORKS NOW!!! :D
Many thanks to Laurent ^^

 

anything