Better way to exit the main loop
authorEleni Maria Stea <estea@igalia.com>
Tue, 30 Apr 2019 13:04:05 +0000 (16:04 +0300)
committerEleni Maria Stea <estea@igalia.com>
Tue, 30 Apr 2019 15:42:05 +0000 (18:42 +0300)
src/main.cc

index 65ed3f2..63d7946 100644 (file)
@@ -35,6 +35,8 @@ static float cam_phi, cam_theta, cam_dist = 10;
 static unsigned int sdrprog;
 static int uloc_cam_xform = -1;
 
+static bool quit;
+
 int main(int argc, char **argv)
 {
        glutInit(&argc, argv);
@@ -56,12 +58,10 @@ int main(int argc, char **argv)
        if(!init(argv[1]))
                return 1;
 
-       atexit(cleanup);
-
        Display *dpy = glXGetCurrentDisplay();
        int xfd = ConnectionNumber(dpy);
 
-       for(;;) {
+       while(!quit) {
                if(!redraw_pending) {
                        int num_rfds;
                        int *rfds = resman_get_wait_fds(sdrman, &num_rfds);
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
                redraw_pending = false;
                glutMainLoopEvent();
        }
+       cleanup();
 }
 
 static bool init(const char *fname)
@@ -162,8 +163,8 @@ static void keyboard(unsigned char key, int x, int y)
 {
        switch(key) {
        case 27:
-               glutLeaveMainLoop();
-               exit(0);
+               quit = true;
+               break;
        default:
                break;
        }