printf - Game Crashing

Started by
12 comments, last by Narcis 17 years, 11 months ago
I've been scanning this for a while, and I can't figure out why the game keeps crashing. I'm using HGE and I've narrowed it down to this line...

hge_font->printf(200, 215, "You are a %s, %s %s. You have a %s \n%s\n\n%s",
 TranslateGender(gender), TranslatecType(ctype), TranslateRace(race),
 TranslateDescription(rndClr), TranslateMind(mind), TranslateRaceType(race));
Just wondering if someone can point out my mistake? Or perhaps suggest a better way to do things.
Advertisement
Look at the debugger and see if all the values you are passing are valid.

theTroll
Yeah, make certain that all the values you're passsing to Translate<whatever>() aren't NULL and that the returns from those function calls aren't NULL either.
Quote:Original post by Narcis
Or perhaps suggest a better way to do things.


How about "Don't use the elipsis construct"?[smile]

But seriously, you are not giving us enough information. You seem to be using some kind of library, so you should check its documentation and make sure that the types of the parameters you are passing are what the function expects. printf style functions can't have compile-time type saftey, so you have to be extra careful.
Ok, well, do you have the option to use the standard library for this operation. There are so many things wrong with printf when considering the C++ standard that it doesn't bare using.

Dave
Quote:Look at the debugger and see if all the values you are passing are valid.


Program received signal (SIGSEGV)Segmentation faultCannot access memory at address 0x6d206120error


Quote:Yeah, make certain that all the values you're passsing to Translate<whatever>() aren't NULL and that the returns from those function calls aren't NULL either.


Check, and all have values.

Quote:But seriously, you are not giving us enough information. You seem to be using some kind of library, so you should check its documentation and make sure that the types of the parameters you are passing are what the function expects. printf style functions can't have compile-time type saftey, so you have to be extra careful.


HGE printf function works exactly like printf without HGE.

Quote:Ok, well, do you have the option to use the standard library for this operation.


Actually I need to use hge for it.
Make sure all those Translate functions are returning the valid values.

(If you're using VC++, go to the Immediate window and type them in ala TranslateGender(gender)<ENTER>)

If they are, is your font working properly?

(Can you print a test message with printf? If not, can you with Render?)
Anthony Umfer
Everything is returning valid values, however I just took out the last argument in that line, and used Render() to print that little peice of information, and it works fine - I suspect that printf can only print an limited amount of characters...

So now this works:
hge_font->printf(200, 215, "You are a %s, %s %s. You have a %s \n%s\n\n", TranslateGender(gender), TranslatecType(ctype), TranslateRace(race), TranslateDescription(rndClr), TranslateMind(mind));hge_font->Render(200, 300, TranslateRaceType(race));


[Edited by - Narcis on May 1, 2006 9:37:26 PM]
lemme guess, the printf function in hge_font looks something like:

void hge_font::printf(int x, int y, const char* format, ...) {   va_list args;   va_start(args, format);   char buffer[256];   vsprintf(buffer, args);


and it is overflowing the internal buffer. At very least it should be vsnprintf instead so it wouldn't crash.
TranslateRace(), etc do return a char* and not a std::string, right?

This topic is closed to new replies.

Advertisement