Hello,
On Linux/Unix, when you change the system time (for instance, using
settimeofday), OSG animations will freeze your application because
osg::Timer uses gettimeofday internally on non-Win32 platforms. This
is wrong and should be replace with times(2) or clock_gettime(2).
The attached patch fixes the issue in a binary-compatible way by using
clock_gettime when it's available, and falling back to gettimeofday
when it's not.
--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
diff -rupd openscenegraph-2.9.5.orig/OpenSceneGraph/src/osg/Timer.cpp openscenegraph-2.9.5/OpenSceneGraph/src/osg/Timer.cpp
--- openscenegraph-2.9.5.orig/OpenSceneGraph/src/osg/Timer.cpp 2009-07-27 15:03:59.000000000 +0200
+++ openscenegraph-2.9.5/OpenSceneGraph/src/osg/Timer.cpp 2009-07-28 13:40:32.000000000 +0200
@@ -72,8 +72,6 @@ Timer* Timer::instance()
#else
- #include <sys/time.h>
-
Timer::Timer( void )
{
_secsPerTick = (1.0 / (double) 1000000);
@@ -81,11 +79,24 @@ Timer* Timer::instance()
setStartTick();
}
- Timer_t Timer::tick() const
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return ((osg::Timer_t)tv.tv_sec)*1000000+(osg::Timer_t)tv.tv_usec;
- }
+ #if defined(_POSIX_TIMERS) && ( _POSIX_TIMERS > 0 ) && defined(_POSIX_MONOTONIC_CLOCK)
+ #include <time.h>
+
+ Timer_t Timer::tick() const
+ {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ((osg::Timer_t)ts.tv_sec)*1000000+(osg::Timer_t)ts.tv_nsec*1000;
+ }
+ #else
+ #include <sys/time.h>
+
+ Timer_t Timer::tick() const
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return ((osg::Timer_t)tv.tv_sec)*1000000+(osg::Timer_t)tv.tv_usec;
+ }
+ #endif
#endif
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org