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

Author Topic: Font crash at game exit  (Read 2981 times)

0 Members and 2 Guests are viewing this topic.

Sticky

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font crash at game exit
« on: November 23, 2009, 10:48:59 am »
I'm not sure what I'm doing wrong, but whenever I exit my game, it crashes with a segfault.
Quote
Program received signal SIGSEGV, Segmentation fault.
In atioglxx!DrvReleaseContext () (C:\WINDOWS\system32\atioglxx.dll)


I know about the bug of using the default font, but I thought the way I'd gone around it should avoid this issue. The way I've set it up is, in my header file for the class I have:
Code: [Select]
sf::Font fFont;
sf::String sSquared;
sf::String sPow2;
sf::String sSubtitle;


And then in the class constructor I have:
Code: [Select]
if(!fFont.LoadFromFile("resources/Fonts/font.ttf", 56))
printf("Failed loading font");

sSquared = sf::String("text", fFont, 56);
// Other stuff to set up sSquared

sPow2 = sf::String("2", fFont, 24);
// Other stuff to set up sPow2

sSubtitle = sf::String("ssubtitle", fFont, 32);
// Other stuff to set up sSubtitle


If I comment out or remove all of the String and Font code, the game runs without issues.

If there is another way to do this that I'm not aware of, please correct me. Otherwise, I've got it so that the font is being loaded into the String directly into the constructor, like you said. The game loads fine and renders the text, but if I try to use "delete & fFont" or on any of the Strings, it will crash immediately; or, when you try to exit the game it will crash with a memory error about being unable to read\write the selected memory.

To pre-empt any questions about my setup, I'm using the dynamic libraries on Windows XP. My graphics drivers are up to date as far as I know, but the card itself is pretty outdated.

Any help in this matter is appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Font crash at game exit
« Reply #1 on: November 23, 2009, 03:52:14 pm »
There's at least one new topic about this issue every week. I think there was one two days ago.

--> it's a known bug, and the possible workarounds are written in several (too many!) messages on this forum ;)
Laurent Gomila - SFML developer

Sticky

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Font crash at game exit
« Reply #2 on: November 25, 2009, 08:53:39 am »
Quote from: "Laurent"
it's a known bug

Quote from: "Sticky"
I know about the bug of using the default font


Quote from: "Laurent"
and the possible workarounds are written in several (too many!) messages on this forum ;)

Quote from: "Sticky"
I've got it so that the font is being loaded into the String directly into the constructor, like you said.

Quote from: "Laurent"
It's a know bug.

Two workarounds exist:
- never construct a sf::String with the default font (always pass yours directly to the constructor)
- use the static SFML libraries

Apart from that, I don't want to link statically as it makes everything more difficult to manage.

Quote from: "Sticky"
If there is another way to do this that I'm not aware of, please correct me.


Also if
Quote from: "Laurent"
written in several (too many!) messages
then why don't you just write it once and make it a pinned topic in the graphics forum? Surely this would stop the issues being posted to an extent and leave you with less time having to moderate all of these posts on the forum.

I guess what I was actually trying to ask in my first post was if the way I had it laid out (as in, declaration in the header and then creation in the constructor) was the correct way to do it. Clearly it isn't, because of the errors, hence the question.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Font crash at game exit
« Reply #3 on: November 25, 2009, 09:14:36 am »
Oops, I'm sorry, I guess I read your message too quickly.

Quote
guess what I was actually trying to ask in my first post was if the way I had it laid out (as in, declaration in the header and then creation in the constructor) was the correct way to do it. Clearly it isn't, because of the errors, hence the question.

You're right, it's not correct. You're initializaing your strings with the assignment operator, which means that they were already (default-)constructed, which means that the built-in default font was used.

To avoid the crash you should use the initialization list of the constructor:
Code: [Select]
YourClass::YourClass() :
sSquared("text", fFont, 56),
sPow2("2", fFont, 24),
sSubtitle("ssubtitle", fFont, 32)
{
}

But since the fFont object is not initialized yet... it's not really possible in this case. Unless you write a function that returns the font, and use it in your constructor:
Code: [Select]
YourClass::YourClass() :
fFont(LoadFont()),
sSquared("text", fFont, 56),
sPow2("2", fFont, 24),
sSubtitle("ssubtitle", fFont, 32)
{
}

But that's becoming ugly :)
Laurent Gomila - SFML developer

Sticky

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font crash at game exit
« Reply #4 on: November 25, 2009, 09:28:29 am »
Alright, thanks for that. I'll have a look into the initialisation lists and see what I can do.

Edit:
Yep, works great. Thank you very much for that help!