From f50c5f7a5e04bcd6be4fe797abf6b8d5bab0ca1c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 23 Mar 2002 21:28:25 +0000 Subject: [PATCH] Moved the exit on escape into Window, and added a virtual free method on both Window an Viewer to clean up the windows, this is now called before exit is finally called, ensure that more more memroy is clean up prior to exit. --- include/osgGLUT/Viewer | 3 +++ include/osgGLUT/Window | 5 +++++ src/osgGLUT/Viewer.cpp | 29 ++++++++++++++++++++++------- src/osgGLUT/Window.cpp | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index 1a76fc2fd..b71d1791f 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -96,6 +96,8 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter protected: + virtual void clear(); + virtual void display(); virtual void reshape(GLint w, GLint h); virtual void mouseMotion(int x, int y); @@ -142,6 +144,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter } times[3]; // store up to 3 frames worth of times bool _useDisplayLists; + osg::Timer _timer; osg::Timer_t _tickRatePerSecond; osg::Timer_t _initialTick; diff --git a/include/osgGLUT/Window b/include/osgGLUT/Window index 541072da0..0b51784e6 100644 --- a/include/osgGLUT/Window +++ b/include/osgGLUT/Window @@ -31,6 +31,8 @@ class OSGGLUT_EXPORT Window protected: + virtual void clear(); + static void displayCB(); static void reshapeCB(int w, int h); static void visibilityCB(int state); @@ -68,6 +70,9 @@ class OSGGLUT_EXPORT Window bool _fullscreen; int _saved_wx, _saved_wy, _saved_ww,_saved_wh; + bool _exit; + void check_if_exit(); + }; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index aa599d73a..5f4578889 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -128,6 +128,16 @@ Viewer::~Viewer() { } +void Viewer::clear() +{ + _viewportList.clear(); + _frameStamp = 0L; + _displaySettings = 0L; + + Window::clear(); +} + + /** read the command line string list, removing any matched control sequences.*/ void Viewer::readCommandLine(std::vector& commandLine) { @@ -1106,13 +1116,18 @@ void Viewer::keyboard(unsigned char key, int x, int y) break; case 27 : - // Escape - #ifdef __MWERKS__ - std::exit(0); // avoid collision of std::exit(..) / exit(..) compile errors. - #else - exit(0); - #endif - break; + + _exit = true; + +// +// // Escape +// #ifdef __MWERKS__ +// std::exit(0); // avoid collision of std::exit(..) / exit(..) compile errors. +// #else +// exit(0); +// #endif +// break; + } } diff --git a/src/osgGLUT/Window.cpp b/src/osgGLUT/Window.cpp index 864afea5f..e0ed23e03 100644 --- a/src/osgGLUT/Window.cpp +++ b/src/osgGLUT/Window.cpp @@ -33,6 +33,9 @@ Window::Window() _mx = _ww/2, _my = _wh/2; _mbutton = 0; + + _exit = false; + } @@ -40,6 +43,9 @@ Window::~Window() { } +void Window::clear() +{ +} /** * Configure and open the GLUT window for this Window @@ -82,6 +88,7 @@ bool Window::open() void Window::displayCB() { s_theWindow->display(); + s_theWindow->check_if_exit(); } @@ -89,56 +96,66 @@ void Window::displayCB() void Window::reshapeCB(int w, int h) { s_theWindow->reshape(w, h); + s_theWindow->check_if_exit(); } void Window::visibilityCB( int state ) { s_theWindow->visibility(state); + s_theWindow->check_if_exit(); } void Window::mouseCB(int button, int state, int x, int y) { s_theWindow->mouse(button, state, x, y); + s_theWindow->check_if_exit(); } void Window::mouseMotionCB(int x, int y) { s_theWindow->mouseMotion(x,y); + s_theWindow->check_if_exit(); } void Window::mousePassiveMotionCB(int x, int y) { s_theWindow->mousePassiveMotion(x,y); + s_theWindow->check_if_exit(); } void Window::keyboardCB(unsigned char key, int x, int y) { s_theWindow->keyboard(key,x,y); + s_theWindow->check_if_exit(); } void Window::specialCB(int key, int x, int y) { s_theWindow->special(key,x,y); + s_theWindow->check_if_exit(); } void Window::spaceballMotionCB(int x, int y, int z) { s_theWindow->spaceballMotion(x,y,z); + s_theWindow->check_if_exit(); } void Window::spaceballRotateCB(int x, int y, int z) { s_theWindow->spaceballRotate(x,y,z); + s_theWindow->check_if_exit(); } void Window::spaceballButtonCB(int button, int state) { s_theWindow->spaceballButton(button,state); + s_theWindow->check_if_exit(); } @@ -236,3 +253,18 @@ bool Window::run() return true; } + +void Window::check_if_exit() +{ + if (_exit) + { + clear(); + + #ifdef __MWERKS__ + std::exit(0); // avoid collision of std::exit(..) / exit(..) compile errors. + #else + exit(0); + #endif + } +} +