glut atexit() stack overflow

Started by
0 comments, last by GameDev.net 17 years, 5 months ago
so i have a basic app where I show a glut window and don't draw anything. I register a callback function for glut's atexit() function and everything works as it should except for when I exit the app i get a stack overflow exception. if I remove the atexit() callback i get no exception. Anyone know what could cause this? I have very minimal code


void onExit();
void tick();
void init();
void display();
void reshape(int w, int h);

int main(int argc, char *argv[])
{
     glutInit(&argc,argv);
     glutInitWindowPosition(100,100);
     glutInitWindowSize(800,600);
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

     glutCreateWindow("Project Soldier - by Flavius Alecu");
     atexit(onExit);
     glutDisplayFunc(display);
     glutIdleFunc(tick);
     glutReshapeFunc(reshape);

     glutMainLoop();

     return 0;
}

void onExit()
{
}


void tick()
{
	glutPostRedisplay();
}

void reshape(int w, int h)
{
     if (h == 0)
     {
        h = 1;
     }
     glViewport(0,0,w,h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();

     glOrtho(0, w, h, 0, 0, 1);

     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity(); 
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    glutSwapBuffers();
}


EDIT: sorry, i forgot...I have the following line in the onExit() function also: exit(0); That's what give the exception. Although I remember that I used to have it there before, don't really know why, and never got the exception before. [Edited by - Flawe on November 9, 2006 7:32:17 AM]

Making Terralysia, wishlist now on Steam <3!

Advertisement
Your atexit callback is called when the program exits. If you call exit() within that callback, your program will recursively call your atexit callback because it keeps attempting to exit. This will give you a stack overflow.

This topic is closed to new replies.

Advertisement