From 0d2f235b5773e0403b7a121dd8bd1b4621b25abf Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Tue, 24 Jul 2012 15:03:53 +0000 Subject: [PATCH] added warning and error callbacks to demo git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1369 7f0cb862-5218-0410-a997-914c9d46530a --- progs/demos/CallbackMaker/CallbackMaker.c | 40 ++++++++++++++++++++++++++++- src/fg_menu.c | 1 - 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c index ac127fb..5abd8ee 100644 --- a/progs/demos/CallbackMaker/CallbackMaker.c +++ b/progs/demos/CallbackMaker/CallbackMaker.c @@ -131,6 +131,40 @@ Display(void) glutSwapBuffers(); } +static void +Warning(const char *fmt, va_list ap) +{ + printf("%6d Warning callback:\n"); + + /* print warning message */ + vprintf(fmt, ap); +} + +static void +Error(const char *fmt, va_list ap) +{ +#define STRING_LENGTH 10 + char dummy_string[STRING_LENGTH]; + printf("%6d Error callback:\n"); + + /* print warning message */ + vprintf(fmt, ap); + + /* deInitialize the freeglut state */ + /* This all goes haywire of course when the error occurs during deinitialize, + * one might want to call exit directly as its possible freeglut is messed + * up internally when error is called. + */ + printf("Error callback: calling glutExit() to prepare for clean exit\n"); + glutExit(); + + /* terminate program */ + printf ( "Please enter something to exit: " ); + fgets ( dummy_string, STRING_LENGTH, stdin ); + + exit(1); +} + static void Reshape(int width, int height) { @@ -407,7 +441,9 @@ MenuDestroy( void ) menudestroy_called = 1 ; printf ( "%6d Window %d MenuDestroy Callback\n", ++sequence_number, window ) ; - glutPostRedisplay () ; + + if (window) /* When destroyed when shutting down, not always a window defined... */ + glutPostRedisplay () ; } static void @@ -434,6 +470,8 @@ main(int argc, char *argv[]) int menuID, subMenuA, subMenuB; + glutInitWarningFunc(Warning); + glutInitErrorFunc(Error); glutInitWindowSize(500, 250); glutInitWindowPosition ( 140, 140 ); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE ); diff --git a/src/fg_menu.c b/src/fg_menu.c index fb5f4a5..f96295b 100644 --- a/src/fg_menu.c +++ b/src/fg_menu.c @@ -545,7 +545,6 @@ static void fghActivateMenu( SFG_Window* window, int button ) window->State.MouseY + glutGet( GLUT_WINDOW_Y ) - menu->Y; /* Menu status callback */ - printf("Menu status callback: %p\n",fgState.MenuStatusCallback); if (fgState.MenuStateCallback || fgState.MenuStatusCallback) { fgStructure.CurrentMenu = menu; -- 1.7.10.4