Sign in to follow this  

Subtle bug in lesson 14

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

This topic is 4248 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this