Jump to content
  • Advertisement
Sign in to follow this  
Fritz__

Subtle bug in lesson 14

This topic is 4468 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

Hey, Just wanted to let you guys know about a bug in lesson 14: there's a place in glPrint() where the gmf array is indexed via the character value: for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { length+=gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width } Where text is defined as: char text[256]; The problem arises when you have a character value greater than (decimal)127. Then text[loop] becomes negative, since char is signed, and the program exhibits memory problems. One bug fix is to cast it as an unsigned char in the index: length+=gmf[(unsigned char)text[loop]].gmfCellIncX; This bug won't be evident unless you plan to use characters outside of the normal ascii range, of course... cheers, Fritz Renema

Share this post


Link to post
Share on other sites
Advertisement
merely seeing this alone in a c++ tutorial makes me cringe:

GLvoid glPrint(const char *fmt, ...)

then again i'm a member of the type safety nazi ninja squad.

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!