From 6a67b66e8e479bdfdeafee2b1bde6fadb1843bcd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Apr 2007 16:15:41 +0000 Subject: [PATCH] Added delay between sequential threading model changes to prevent the system from locking up with 'm' is held down, which previous would cause the threading model to be thrashed. --- applications/osgviewer/osgviewer.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index bcd2dd750..1f3a662ae 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -34,7 +34,11 @@ class ThreadingHandler : public osgGA::GUIEventHandler { public: - ThreadingHandler() {} + ThreadingHandler() + { + _tickOrLastKeyPress = osg::Timer::instance()->tick(); + } + bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { @@ -45,8 +49,14 @@ public: { case(osgGA::GUIEventAdapter::KEYUP): { - if (ea.getKey()=='m') + + double delta = osg::Timer::instance()->delta_s(_tickOrLastKeyPress, osg::Timer::instance()->tick()); + + if (ea.getKey()=='m' && delta>1.0) { + + _tickOrLastKeyPress = osg::Timer::instance()->tick(); + switch(viewer->getThreadingModel()) { case(osgViewer::Viewer::SingleThreaded): @@ -101,8 +111,7 @@ public: usage.addKeyboardMouseBinding("e","Toggle the placement of the end of frame barrier."); } - - + osg::Timer_t _tickOrLastKeyPress; bool _done; };