Jump to content
  • Advertisement
Sign in to follow this  
Narcis

printf - Game Crashing

This topic is 4457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Quote:
Look at the debugger and see if all the values you are passing are valid.



Program received signal (SIGSEGV)
Segmentation fault
Cannot access memory at address 0x6d206120
error


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.

Share this post


Link to post
Share on other sites
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?)

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!