Hey guys, I've been teaching myself SDL to start out w/ a simple API, using LazyFoo's tutorials. I created a Tic Tac Toe program, which works great in Windows XP, under Code::Blocks. When I tried running the code in Ubuntu 9.10 under Code::Blocks I get a segmentation fault. I recalled reading that TTF_RenderText_Solid may not work under linux, so I tried using both RenderText_Shaded and RenderText_Blended, but wound up getting the same error...this is the chunk of code I believe to be the culprit.
Code:
void printScoreBoard(){
int relwidth = (SCREENWIDTH - scores->w)/2; // FOR BUTTONS
int relheight = (SCREENHEIGHT - scores->h)/2;
int coords[3] = {relwidth+54,relwidth+115,relwidth+182};
char buffer[5] = {'\0','\0','\0','\0','\0'};
redrawBoard();
applySurface(relwidth,relheight,scores,screen);
for (int i = 0; i < 3; i++){
sprintf(buffer,"%d",scoreboard[i]); // Scoreboard is a var holding wins and whatnot
if (!(message = TTF_RenderText_Blended(font,buffer,textColor)))
printf("Oh My Goodness, an error : %s", TTF_GetError());
else
applySurface(coords[i],relheight+209,message,screen);
} // CLSP is a constant specifying the location of the button to clear scores in the sprite
applySurface(relwidth+35,relheight+268,buttons,screen,&mclip[CLSP]);
}
The disassembly of memory shows the crash happening here:
Code:
0x80495fe mov eax,DWORD PTR [ebp+eax*4-0x28]
if that's of any use...
Essentially the C++ code is supposed to print the "score" of the current game, based on X wins, O wins, and Ties, using TTF fonts to display the score...
Here's some screenshots
http://i93.photobucket.com/albums/l5...an/screen2.jpg
http://i93.photobucket.com/albums/l5...an/screen3.jpg
I read the TTF documentation on the functions, which say that passing a NULL font can cause a segfault, and that passing NULL text causes undefined behavior, but I defined the font, and I'm linking against SDL_ttf and freetype...so I'm at a complete loss...does anyone know a workaround or something that I can use?
I attached the full cpp file, it was 342 lines so I didn't think it was really good etiquette to paste it all here ^_^