what the?!

Started by
3 comments, last by swiftcoder 19 years, 7 months ago
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?
Advertisement
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.
Argh forgot to login...
Quote:Original post by Anonymous Poster who was really uavfun
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.


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}
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.

[edit]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

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement