NOTE: I also posted this in the OSG mailing list.

Hi,

I have mixed Qt and OSG to create a viewer for the PCL library OutOfCore trees (using the wrapper classes of osgpcl written by Adam Stambler: https://github.com/adasta/osgpcl).

I started with the osgQtViewer example and changed it accordingly with my needs. Using Windows 7 64 bits, the viewer works great.
Now, I tried to run the viewer in 32 bits and got an assertion error from Eigen that I could overpass including this in my class:

EIGEN_MAKE_ALIGNED_OPERATOR_NEW

But then I got a new error about constructing a QWidget before a QApplication when creating the graphics context:

Qt Code:
  1. osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
To copy to clipboard, switch view to plain text mode 

This was due to mixing debug and release libraries.

Now, using only release libraries I got rid of that error and the viewer widget window appears, but when it is about to show the OutOfCore tree, the app segfaults with this error:

Qt Code:
  1. QWidget::releaseDC(): failed to release HDC (El identificador del contexto de dispositivo (DC) no es v?lido.)
To copy to clipboard, switch view to plain text mode 

My viewer class inherits both from QWidget and from osg::CompositeViewer. Here is how the widget is called:

Qt Code:
  1. // The widget already exists. It is created in the main thread with some default values. No camera, no graphics context.
  2. widget->AddCloud();
  3.  
  4. osg::Vec3d eye, up;
  5.  
  6. widget->getCameraManipulator()->getHomePosition(eye, center, up);
  7.  
  8. distance = widget->getCameraManipulator()->getFusionDistanceValue();
To copy to clipboard, switch view to plain text mode 


And the involved methods from the OSG+Qt Viewer:

Qt Code:
  1. void QOSGViewer::AddCloud(void) {
  2.  
  3. std::cout << "Loading cloud from file: " << cloud_file.c_str() << "\n";
  4.  
  5. int fileformat_idx( cloud_filepath.find(".pcd") );
  6.  
  7. std::string aux( cloud_filepath.substr(0, fileformat_idx) );
  8.  
  9. aux += "_octree/tree.oct_idx";
  10.  
  11. QWidget* widget = AddViewWidget(
  12.  
  13. CreateCamera(0,0,100,100),
  14.  
  15. ReadOctree(aux)
  16.  
  17. );
  18.  
  19. qDebug() << "YAY"; // REACHES THIS
  20.  
  21. QGridLayout* grid = new QGridLayout;
  22.  
  23. grid->setContentsMargins(1,1,1,1);
  24.  
  25. grid->addWidget( widget, 0, 0 );
  26.  
  27. this->setLayout( grid );
  28.  
  29. }
  30.  
  31.  
  32. osg::Camera* QOSGViewer::CreateCamera(
  33.  
  34. int x,
  35.  
  36. int y,
  37.  
  38. int w,
  39.  
  40. int h,
  41.  
  42. const std::string &name,
  43.  
  44. bool windowDecoration
  45.  
  46. ) {
  47.  
  48. osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
  49.  
  50. osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
  51.  
  52. traits->windowName = name;
  53.  
  54. traits->windowDecoration = windowDecoration;
  55.  
  56. traits->x = x;
  57.  
  58. traits->y = y;
  59.  
  60. traits->width = w;
  61.  
  62. traits->height = h;
  63.  
  64. traits->doubleBuffer = true;
  65.  
  66. traits->alpha = ds->getMinimumNumAlphaBits();
  67.  
  68. traits->stencil = ds->getMinimumNumStencilBits();
  69.  
  70. traits->sampleBuffers = ds->getMultiSamples();
  71.  
  72. traits->samples = ds->getNumMultiSamples();
  73.  
  74. osg::ref_ptr<osg::Camera> camera = new osg::Camera;
  75.  
  76. // camera = new osg::Camera;
  77.  
  78. osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
  79.  
  80. camera->setGraphicsContext( gc.get() );
  81.  
  82. camera->setClearColor( osg::Vec4(0,0,0,1) );
  83.  
  84. camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
  85.  
  86. camera->setProjectionMatrixAsPerspective(
  87.  
  88. 30.0f,
  89.  
  90. static_cast<double>(traits->width)/static_cast<double>(traits->height),
  91.  
  92. 1.0f,
  93.  
  94. 10000.0f
  95.  
  96. );
  97.  
  98. return camera.release();
  99.  
  100. }
  101.  
  102. osg::Node* QOSGViewer::ReadOctree(const std::string &file) {
  103.  
  104. osg::Group* group = new osg::Group;
  105.  
  106. group->addChild( osgDB::readNodeFile(file, options) );
  107.  
  108. return group;
  109.  
  110. }
  111.  
  112. QWidget* QOSGViewer::AddViewWidget(
  113.  
  114. osg::Camera *camera,
  115.  
  116. osg::Node *scene
  117.  
  118. ) {
  119.  
  120. osgViewer::View* view = new osgViewer::View;
  121.  
  122. // view = new osgViewer::View;
  123.  
  124. view->setCamera( camera );
  125.  
  126. view->setSceneData( scene );
  127.  
  128. addView( view );
  129.  
  130. view->addEventHandler( new osgViewer::StatsHandler );
  131.  
  132. view->setCameraManipulator( new osgGA::TrackballManipulator );
  133.  
  134. osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
  135.  
  136. camera->getGraphicsContext()
  137.  
  138. );
  139.  
  140. return gw ? gw->getGLWidget() : 0;
  141.  
  142. }
To copy to clipboard, switch view to plain text mode 

Can you please tell me where I'm failing? I'm clueless about this crash.

Best regards,
Adrián.