Blob Blame History Raw
From 636d27ef0359ee6a293ad7af1cf0dd4d34a3d3f8 Mon Sep 17 00:00:00 2001
From: Robert OSFIELD <robert.osfield@gmail.com>
Date: Fri, 20 Mar 2015 11:48:21 +0000
Subject: [PATCH 3/4] From Jannik Heller, "Fix for Qt4 multi-threaded crash.
 This patch adds the AA_X11InitThreads flag to the QApplication setup, meaning
 QT will call XInitThreads for us. This also bumps the required QT version to
 4.8+, because the AA_X11InitThreads flag was introduced in that version. If
 that is not acceptable, we could add a QT_VERSION >= 0x040800 guard, or
 manually call XInitThreads() instead. Let me know what you think."

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14804 16af8721-9629-0410-8352-f15c8da7e697
---
 examples/osgviewerQt/osgviewerQt.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/examples/osgviewerQt/osgviewerQt.cpp b/examples/osgviewerQt/osgviewerQt.cpp
index 5e3917d..52ac446 100644
--- a/examples/osgviewerQt/osgviewerQt.cpp
+++ b/examples/osgviewerQt/osgviewerQt.cpp
@@ -105,6 +105,12 @@ int main( int argc, char** argv )
     while (arguments.read("--DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext;
     while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext;
 
+#if QT_VERSION >= 0x040800
+    // Required for multithreaded QGLWidget on Linux/X11, see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/
+    if (threadingModel != osgViewer::ViewerBase::SingleThreaded)
+        QApplication::setAttribute(Qt::AA_X11InitThreads);
+#endif
+    
     QApplication app(argc, argv);
     ViewerWidget* viewWidget = new ViewerWidget(threadingModel);
     viewWidget->setGeometry( 100, 100, 800, 600 );
-- 
2.4.3