🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Subtle bug in lesson 14
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
merely seeing this alone in a c++ tutorial makes me cringe:
then again i'm a member of the type safety nazi ninja squad.
GLvoid glPrint(const char *fmt, ...)
then again i'm a member of the type safety nazi ninja squad.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement