• 15
• 15
• 11
• 9
• 10

Subtle bug in lesson 14

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

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 on other sites
GLvoid glPrint(const char *fmt, ...)