kio.marv
28th October 2013, 16:18
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:
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
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:
QWidget::releaseDC(): failed to release HDC (El identificador del contexto de dispositivo (DC) no es v?lido.)
My viewer class inherits both from QWidget and from osg::CompositeViewer. Here is how the widget is called:
// The widget already exists. It is created in the main thread with some default values. No camera, no graphics context.
widget->AddCloud();
osg::Vec3d eye, up;
widget->getCameraManipulator()->getHomePosition(eye, center, up);
distance = widget->getCameraManipulator()->getFusionDistanceValue();
And the involved methods from the OSG+Qt Viewer:
void QOSGViewer::AddCloud(void) {
std::cout << "Loading cloud from file: " << cloud_file.c_str() << "\n";
int fileformat_idx( cloud_filepath.find(".pcd") );
std::string aux( cloud_filepath.substr(0, fileformat_idx) );
aux += "_octree/tree.oct_idx";
QWidget* widget = AddViewWidget(
CreateCamera(0,0,100,100),
ReadOctree(aux)
);
qDebug() << "YAY"; // REACHES THIS
QGridLayout* grid = new QGridLayout;
grid->setContentsMargins(1,1,1,1);
grid->addWidget( widget, 0, 0 );
this->setLayout( grid );
}
osg::Camera* QOSGViewer::CreateCamera(
int x,
int y,
int w,
int h,
const std::string &name,
bool windowDecoration
) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
// camera = new osg::Camera;
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
camera->setGraphicsContext( gc.get() );
camera->setClearColor( osg::Vec4(0,0,0,1) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height),
1.0f,
10000.0f
);
return camera.release();
}
osg::Node* QOSGViewer::ReadOctree(const std::string &file) {
osg::Group* group = new osg::Group;
group->addChild( osgDB::readNodeFile(file, options) );
return group;
}
QWidget* QOSGViewer::AddViewWidget(
osg::Camera *camera,
osg::Node *scene
) {
osgViewer::View* view = new osgViewer::View;
// view = new osgViewer::View;
view->setCamera( camera );
view->setSceneData( scene );
addView( view );
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext()
);
return gw ? gw->getGLWidget() : 0;
}
Can you please tell me where I'm failing? I'm clueless about this crash.
Best regards,
Adrián.
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:
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
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:
QWidget::releaseDC(): failed to release HDC (El identificador del contexto de dispositivo (DC) no es v?lido.)
My viewer class inherits both from QWidget and from osg::CompositeViewer. Here is how the widget is called:
// The widget already exists. It is created in the main thread with some default values. No camera, no graphics context.
widget->AddCloud();
osg::Vec3d eye, up;
widget->getCameraManipulator()->getHomePosition(eye, center, up);
distance = widget->getCameraManipulator()->getFusionDistanceValue();
And the involved methods from the OSG+Qt Viewer:
void QOSGViewer::AddCloud(void) {
std::cout << "Loading cloud from file: " << cloud_file.c_str() << "\n";
int fileformat_idx( cloud_filepath.find(".pcd") );
std::string aux( cloud_filepath.substr(0, fileformat_idx) );
aux += "_octree/tree.oct_idx";
QWidget* widget = AddViewWidget(
CreateCamera(0,0,100,100),
ReadOctree(aux)
);
qDebug() << "YAY"; // REACHES THIS
QGridLayout* grid = new QGridLayout;
grid->setContentsMargins(1,1,1,1);
grid->addWidget( widget, 0, 0 );
this->setLayout( grid );
}
osg::Camera* QOSGViewer::CreateCamera(
int x,
int y,
int w,
int h,
const std::string &name,
bool windowDecoration
) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
// camera = new osg::Camera;
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
camera->setGraphicsContext( gc.get() );
camera->setClearColor( osg::Vec4(0,0,0,1) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height),
1.0f,
10000.0f
);
return camera.release();
}
osg::Node* QOSGViewer::ReadOctree(const std::string &file) {
osg::Group* group = new osg::Group;
group->addChild( osgDB::readNodeFile(file, options) );
return group;
}
QWidget* QOSGViewer::AddViewWidget(
osg::Camera *camera,
osg::Node *scene
) {
osgViewer::View* view = new osgViewer::View;
// view = new osgViewer::View;
view->setCamera( camera );
view->setSceneData( scene );
addView( view );
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext()
);
return gw ? gw->getGLWidget() : 0;
}
Can you please tell me where I'm failing? I'm clueless about this crash.
Best regards,
Adrián.