1

I'm basically having the same "original" problem that this user was having here: C++ SDL segmentation fault .

However, even after installing the font I am trying to use, I still get a Segmentation Fault as soon as I run the program.

I used gdb to debug and it returns with:

TTF_SizeUNICODE (font=font@entry=0x0, text=text@entry=0xbfffefe0, w=w@entry=0xbfffef9c, h=h@entry=0xbfffefa0) at SDL_ttf.c:1127
1127        use_kerning = FT_HAS_KERNING( font->face ) && font->kerning;

Here is how I am loading the TTF font:

TTF_Font *font;
TTF_Init();
font = TTF_OpenFont("/includes/game_over.ttf",30);

Any ideas on what this means?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Quiver
  • 1,351
  • 6
  • 33
  • 56
  • 2
    I see font = 0, then I see font is dereferenced twice (font->face and font->kerning). Why is font equal to 0? – donjuedo Sep 27 '15 at 19:42
  • @donjuedo I'm not sure what you mean by why is font equal to 0. Where do you see that it's equal to 0? Is that what the message is implying? I've added to the OP some code on how I am currently loading the font file to use. – Quiver Sep 27 '15 at 19:50
  • 2
    `font=font@entry=0x0` – erip Sep 27 '15 at 21:37

1 Answers1

4

Font is null because TTF_OpenFont wasn't able to open the font. Add this line right after TTF_OpenFont to see what's the problem (e.g. file is missing? insufficent permissions, etc) Or did you mean includes/game_over.ttf instead of /includes/game_over.ttf which points to root folder?

if(!font) {
    printf("TTF_OpenFont: %s\n", TTF_GetError());
}
Burak Tamtürk
  • 1,237
  • 8
  • 19
  • Thanks! It was having a problem loading the file because of the location I was giving it, like you mentioned. – Quiver Sep 27 '15 at 22:31