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

Author Topic: Error while closing program  (Read 1057 times)

0 Members and 1 Guest are viewing this topic.

HeliumPL

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Error while closing program
« on: July 04, 2013, 11:02:46 pm »
Hi!
I've made a simple function in SFML 2.0 to write some text on screen:
Code: [Select]
sf::Text txt(char* text, int size, sf::Color color, int x, int y)
{
sf::Text txt;
txt.setFont(font);
txt.setString(text);
txt.setCharacterSize(size);
txt.setColor(color);
txt.setPosition(x, y);

return txt;
}
Of course it's displayed this way:
Code: [Select]
window.draw(txt("text", 12, sf::Color::White, 0, 0));
It's causing program to crash while it's closing:
Quote
Unhandled exception at 0x76fb59a6 in Offensive.exe: 0xC0000005: Access violation reading location 0xfeeefef6.

I know that I made a stupid mistake  ;D Please help me :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Error while closing program
« Reply #1 on: July 04, 2013, 11:15:00 pm »
Please read this thread carefully; it helps us to understand your problem better, and you to get more answers.

And you shouldn't use char* for string literals, use const char*.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Error while closing program
« Reply #2 on: July 05, 2013, 08:00:09 am »
Quote
Access violation reading location 0xfeeefef6.
It means you're accessing a freed memory location (a destroyed object).
Laurent Gomila - SFML developer