I'm really having trouble closing my console application with FreeGLUT.
I would like to know what the best way is to take every possible closing, because I don't want any memory leaks (I'm pretty afraid of those).
So I already tried the following, which is giving me an exception like this:
First-chance exception at 0x754e6a6f in myProject.exe: 0x40010005: Control-C.
int main(int argc, char **argv)
if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, true) )
// more code here as well ....
glutCloseFunc(close); // set the window closing function of opengl
close(); // close function if coming here somehow
// keyboardManager is a pointer to a class
// which I want to delete, so no memory will leak.
if(keyboardManager) // do I need this check?
bool CtrlHandler(DWORD fdwCtrlType)
// Handle the CTRL-C signal.
// and the close button
// Pass other signals to the next handler.
// delete the pointer anyway
I use this function:
void glutLeaveMainLoop ( void );
There is more information on their sourceforge page but I never used that functionality:
The glutLeaveMainLoop function causes freeglut to stop the event loop. If the GLUT_ACTION_ON_WINDOW_CLOSE option has been set to GLUT_ACTION_CONTINUE_EXECUTION, control will return to the function which called glutMainLoop; otherwise the application will exit.
It is safe to use
delete on a null pointer, no need to check.