c++ - What is the nicest way to close FreeGLUT? -


i'm having trouble closing console application freeglut.

i know best way take every possible closing, because don't want memory leaks (i'm pretty afraid of those).

so tried following, giving me exception this:

first-chance exception @ 0x754e6a6f in myproject.exe: 0x40010005: control-c.

int main(int argc, char **argv) {     if( setconsolectrlhandler( (phandler_routine) ctrlhandler, true) )     {         // more code here ....           glutclosefunc(close); // set window closing function of opengl         glutmainloop();         close(); // close function if coming here somehow     }     else     {         return 1;     }     return 0; }  void close() {     // keyboardmanager pointer class     // want delete, no memory leak.     if(keyboardmanager) // need check?         delete keyboardmanager; }  bool ctrlhandler(dword fdwctrltype) {     switch(fdwctrltype)     {         // handle ctrl-c signal.         case ctrl_c_event:         // , close button         case ctrl_close_event:           close();           return true;          // pass other signals next handler.          case ctrl_break_event:             return false;      // delete pointer anyway         case ctrl_logoff_event:         case ctrl_shutdown_event:         default:             close();             return false;      }  } 

so goes right is:

  1. closing window of glut
  2. closing console application x
  3. closing window of glut keyboardmanager if(keyboardmanager->iskeydown[27]) glutexit();

what goes wrong is:

  1. closing console application ctrl+c, gives exception above.

this in visual studio 2008 c++.

update

i found exception thrown, because i'm in debug. won't problem. question still open: what elegant way close glut?

atexit() seems work well, maybe can use this?

i use function:

void glutleavemainloop ( void );  

there more information on sourceforge page never used functionality:

the glutleavemainloop function causes freeglut stop event loop. if glut_action_on_window_close option has been set glut_action_continue_execution, control return function called glutmainloop; otherwise application exit.

http://freeglut.sourceforge.net/docs/api.php#eventprocessing

it safe use delete on null pointer, no need check.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -