From f48a4baa4ea1ddc9de5eaec187354010368b7a84 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 Jul 2015 15:56:40 +0000 Subject: [PATCH] =?UTF-8?q?From=20Cory=20Slep=20and=20Robert=20Osfield,=20?= =?UTF-8?q?"When=20using=20Open=20Scene=20Graph=20and=20Qt=20on=20Android,?= =?UTF-8?q?=20the=20resulting=20thread=20that=20an=20application=20develop?= =?UTF-8?q?er=E2=80=99s=20Q*Application=20is=20run=20on=20is=20different?= =?UTF-8?q?=20than=20what=20Qt=20considers=20the=20=E2=80=9Cmain=E2=80=9D?= =?UTF-8?q?=20thread,=20which=20can=20cause=20subtle=20problems.=20This=20?= =?UTF-8?q?is=20because=20Qt=20loads=20native=20libraries=20in=20one=20thr?= =?UTF-8?q?ead,=20and=20later=20runs=20the=20application=20in=20a=20differ?= =?UTF-8?q?ent=20thread.=20They=20delay=20running=20in=20the=20second=20th?= =?UTF-8?q?read=20as=20long=20as=20possible=20as=20they=20have=20a=20nontr?= =?UTF-8?q?ivial=20bootstrapping=20process.=20The=20motivation=20for=20Qt?= =?UTF-8?q?=20having=20this=20second=20thread=20is=20to=20allow=20them=20t?= =?UTF-8?q?o=20remain=20responsive=20to=20both=20Java=20and=20native=20eve?= =?UTF-8?q?nts,=20and=20capture=20events=20that=20would=20otherwise=20be?= =?UTF-8?q?=20=E2=80=9Cmissed=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.4@14964 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgQt/GraphicsWindowQt.cpp | 35 ++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/osgQt/GraphicsWindowQt.cpp b/src/osgQt/GraphicsWindowQt.cpp index d2abca275..869902cb7 100644 --- a/src/osgQt/GraphicsWindowQt.cpp +++ b/src/osgQt/GraphicsWindowQt.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #if (QT_VERSION>=QT_VERSION_CHECK(4, 6, 0)) # define USE_GESTURES @@ -119,18 +120,24 @@ static QtKeyboardMap s_QtKeyboardMap; /// The object responsible for the scene re-rendering. class HeartBeat : public QObject { public: -int _timerId; -osg::Timer _lastFrameStartTime; -osg::observer_ptr< osgViewer::ViewerBase > _viewer; + int _timerId; + osg::Timer _lastFrameStartTime; + osg::observer_ptr< osgViewer::ViewerBase > _viewer; -HeartBeat(); -virtual ~HeartBeat(); -void init( osgViewer::ViewerBase *viewer ); -void stopTimer(); -void timerEvent( QTimerEvent *event ); + virtual ~HeartBeat(); + + void init( osgViewer::ViewerBase *viewer ); + void stopTimer(); + void timerEvent( QTimerEvent *event ); + + static HeartBeat* instance(); +private: + HeartBeat(); + + static QPointer heartBeat; }; -static HeartBeat heartBeat; +QPointer HeartBeat::heartBeat; #if (QT_VERSION < QT_VERSION_CHECK(5, 2, 0)) #define GETDEVICEPIXELRATIO() 1.0 @@ -955,7 +962,7 @@ void osgQt::initQtWindowingSystem() void osgQt::setViewer( osgViewer::ViewerBase *viewer ) { - heartBeat.init( viewer ); + HeartBeat::instance()->init( viewer ); } @@ -971,6 +978,14 @@ HeartBeat::~HeartBeat() stopTimer(); } +HeartBeat* HeartBeat::instance() +{ + if (!heartBeat) + { + heartBeat = new HeartBeat(); + } + return heartBeat; +} void HeartBeat::stopTimer() {