View Full Version : Errors while trying to run (glutInit)

12-08-2001, 10:47 AM
HI I am trying to get a program to run. After ages getting it to compile without errors it now has an error when running (The instruction at "xxxxx" referenced memory at "0xcccccccc". The memory could not be "read".
I think it is related to glutInit because when I comment this out I no longer have the error.
int argc = 1;
char* argv[5];

glutInit(&argc, argv);

Thanks for any help.

12-08-2001, 07:04 PM
Those variables get created by the system and passed to main() for you. The reason they're there is so if you run the program from the command line (like the unix world usually does -- rather than double-clicking on icons), you can pass arguments in to your glut program.

Your code should not redeclare them but should be something like:

int main( int argc , char * * argv )
glutInit( &argc , argv );
// ...

12-09-2001, 03:45 AM
The reason it fails in this case is becasue argv[5] is uninitialized. When you do char *argv[5], you create an array of five character pointers. These pointers are uninitialized, and therefore point "nowhere" (read, to invalid memory). GLUT uses the first pointer to extract application name, and when you pass an uninitialized pointer, it craches. Try this instead.

char *argv[] = {"some string", "another string"};

argv[0] will now be initialized, and GLUT can read from the pointer.