# what the?!

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

## Recommended Posts

hello, i just worked out a wierd bug in my program that i cannot figure out why it did what it did. i have a GLuint which i store my font list, i declare it withen a class. then withen my buildFont function (which is in the same class) i had this typo ... GLuint fontBase = glGenLists (96); as you can see i put the type name infront of fontBase, even though i already declare it ... so when i printed say the text "bcd" it would come out "abc" ... whatever i typed in was an offset off ... and i first fixed the problem my chagning the starting point in my list from 32 to 31 ... but later found the typo ... so leaving the typename on when assigning the variable some how shifted where each byte is stored? how come this isnt an error?

##### Share on other sites
Probably you defined a new local variable with the same name as the old one. This is perfectly legal; basically, the old variable disappears until the new one goes out of scope.

The first time you call glGenLists() it will probably give you a value of 1, so if the old variable was 0, that would account for the shift.

##### Share on other sites
Argh forgot to login...

##### Share on other sites
Quote:
 Original post by Anonymous Poster who was really uavfunProbably you defined a new local variable with the same name as the old one. This is perfectly legal; basically, the old variable disappears until the new one goes out of scope.

Not quite. If you have:

#include <iostream>int i;void function( void ){   int i;   std::cout << i << std::endl; //<-- this is the local var   //... you can do this:   std::cout << ::i << std::endl; //<-- this is the global var}

##### Share on other sites
Quote:
 Original post by MaulingMonkey//... you can do this:std::cout << ::i << std::endl; //<-- this is the global var

Granted, but the local variable would be initialised to 1 (the first value returned from glGenLists()), and the global would still be uninitialised (and, depending on your system, this would be 0), so call glCallLists() with the global as your list base, you are actually starting from one list before the beginning of the allocated display lists.

Having looked again at your example, it seems that your offset is in the other direction, possibly glGenLists() returns 0, and your global was initialised to 1?[/edit]

SwiftCoder

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 12
• 10
• 9
• 15
• 22