Sign in to follow this  
Flawe

glut atexit() stack overflow

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this