• Advertisement
Sign in to follow this  

glut atexit() stack overflow

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement