Segmentation Fault Using Sdl_ttf


Coder

Still Fresh
Joined
Dec 13, 2006
Messages
84
Age
59
Website
Visit site
Hi,

I think I must be doing something wrong here but I'm just not familiar enough with SDL programming to figure out what exactly.

I'm using the official SDK (gp2xsdk_windows.zip) and have created a new project, DevC++ kindly creates a template for it which compiles and runs without problem.

So, as a test I decided to do a "hello world" program. No problems adding SDL_ttf to the includes and I can call TTF_init and TTF_close.

The problem arises when I call TTF_OpenFont. Every time I add it I get a segmentation fault (access Violation). The code I'm using looks like this:

TTF_Font *font;
font=TTF_OpenFont("ariel.ttf", 16);
if(!font) {
printf("TTF_OpenFont: %s\n", SDL_GetError());
// handle error
}

The ariel.ttf file is in the same directory as the application.

I'm stuck now as I can't figure out what is going wrong.

Any help would be appreciated.
 
Hi,

I think I must be doing something wrong here but I'm just not familiar enough with SDL programming to figure out what exactly.

<snip>

TTF_Font *font;
font=TTF_OpenFont("ariel.ttf", 16);
if(!font) {
printf("TTF_OpenFont: %s\n", SDL_GetError());
// handle error
}

The ariel.ttf file is in the same directory as the application.

On the other hand, maybe I just need new glasses. The file that is in the directory is arial.ttf. Despite looking at the code and the filename several times I saw them as the same until I decided to rename both to something else.

This just leaves the question of why it threw a segmentation fault instead of just setting the font to null which would have been picked up by the error checking.
 
Last edited by a moderator:
haha i was about to tell you that but you caught it yourself.

as for why it segfaults, sdl just likes to segfault for every little thing :)
 
Which is really really... puting in nicely, STUPID. But I didn't program it, I'm sure that theres a reason behind it.

Well, I've been working on a c++ project and i think its the 5th time I've been messing with my file loaders to try to get them to work but realized i've again added an s to the end of the filename... as in bricks.png instead of the EXISTING brick.png. Same with my bmp loader... and a few others. And I've done it more than once and such.

And good luck with true type fonts, as far as i can tell SDL_ttf is drastically changed in every version in separate Dev-kits which has drove me to make dynamically generated bitmap fonts which is often more lightweight and organized. (seems to be faster too!)
 
Which is really really... puting in nicely, STUPID. But I didn't program it, I'm sure that theres a reason behind it.

Well, I've been working on a c++ project and i think its the 5th time I've been messing with my file loaders to try to get them to work but realized i've again added an s to the end of the filename... as in bricks.png instead of the EXISTING brick.png. Same with my bmp loader... and a few others. And I've done it more than once and such.

And good luck with true type fonts, as far as i can tell SDL_ttf is drastically changed in every version in separate Dev-kits which has drove me to make dynamically generated bitmap fonts which is often more lightweight and organized. (seems to be faster too!)

i'm sure it's faster...regular fonts have tons of hinting so that they can display nicely at different sizes. screen/bitmap fonts don't require the same amount of calculations. not an expert though, maybe they found a fast way of doing it? i'll probably start playing with sdl_ttf soon rather than waste time code for displaying bitmap fonts until i absolutely need it.
 
Last edited by a moderator:
Yeah, thats what i thought. excessive of SDL_ttf use is a way to slow down games on the PC too, to add...
 
Back
Top