1
votes

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?

1
I see font = 0, then I see font is dereferenced twice (font->face and font->kerning). Why is font equal to 0? - donjuedo
@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
font=font@entry=0x0 - erip

1 Answers

4
votes

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());
}