[osg-users] getGraphicsContext()/getState() segfault issue

6 views
Skip to first unread message

Fabien Boco

unread,
Nov 25, 2016, 11:52:19 AM11/25/16
to osg-...@lists.openscenegraph.org
Hi,

I'm trying to do the folowing :


Code:
m_fboTexture->apply( *camera->getGraphicsContext()->getState() );



But it crashes... More precisely, "applyTexParameters()" crashes. Everything has been initialized.

Here is the complete sequence :


Code:
m_osgViewer = new osgViewer::Viewer();
m_osgViewer->setUpViewerAsEmbeddedInWindow( 0, 0, m_width, m_height );
m_osgViewer->getEventQueue()->windowResize( 0, 0, m_width, m_height );

osg::Camera *camera = m_osgViewer->getCamera();
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
camera->setViewport( 0, 0, m_width, m_height );
camera->setProjectionMatrixAsPerspective( m_fov, m_width / m_height, m_zNear, m_zFar );
camera->setNearFarRatio( m_zNearFarRatio );
camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
camera->setClearColor( m_color );

m_fboTexture = new osg::Texture2D();
m_fboTexture->setTextureSize( m_width, m_height );
m_fboTexture->setInternalFormat( GL_RGBA );
m_fboTexture->setFilter( osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR );
m_fboTexture->setFilter( osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR );
m_fboTexture->apply( *camera->getGraphicsContext()->getState() );

camera->attach( osg::Camera::COLOR_BUFFER, m_fboTexture, 0, 0 );



Seems there's an issue with the graphicsContext or/and State aquisition because this line crashes too :


Code:
unsigned int ctxId = m_osgViewer->getCamera()->getGraphicsContext()->getState()->getContextID();



Thank you!

Cheers,
Fabien[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69500#69500





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Nov 25, 2016, 1:01:06 PM11/25/16
to OpenSceneGraph Users
Hi Fabian,

The most likely cause is that the thread you are calling the
texture->apply() from doesn't have a graphics thread current.

The GraphicdWindowEmbedded is just a adapter class that allows you to
use the OSG with 3rd party SDK's like SDL where the graphics context
is created prior the OSG runs it's graphics.

In general with the OSG you don't usually explicitly call
texture->apply() instead you let the scene graph draw traversal do
this at the appropriate time.

What exactly you should be doing to fix things is something I can't
answer as the context is missing as how yu are creating the graphics
context and why you are doing what you are doing.

Robert.

Fabien Boco

unread,
Nov 28, 2016, 5:11:02 AM11/28/16
to osg-...@lists.openscenegraph.org
I'm trying to mix Qt and OSG contexts according to this implementation : QQuickOSG (https://github.com/Sparadon/qquickosg/blob/master/qquickosg.cpp)

He had initialized the FBO like this (line 332) and then use the FBO Texture id to initialize the Qt side Texture (line 374).

Cheers,
Fabien[/url]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69510#69510

Fabien Boco

unread,
Nov 28, 2016, 5:18:54 AM11/28/16
to osg-...@lists.openscenegraph.org
I'm trying to mix Qt and OSG contexts according to this implementation : QQuickOSG (https://github.com/Sparadon/qquickosg/blob/master/qquickosg.cpp)

He had initialized the FBO like this (line 332) and then use the FBO Texture id to initialize the Qt side Texture (line 374).

My pipeline is a little bit different but I have the same objects and I don't get why my apply() crashes. Maybe it misses up with Qt stuff...

Cheers,
Fabien

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69511#69511

Sebastian Messerschmidt

unread,
Nov 28, 2016, 5:26:39 AM11/28/16
to osg-...@lists.openscenegraph.org

Hi Fabien,

Without looking at your specific code in detail:

There is no graphics context associated with the camera directly after
creating the viewer. Make sure viewer->realize runs before accessing the
guts of context-specific stuff.

Your crash most likely is due to having a nullptr-access to the
graphics-context. Check first if the "camera->getGraphicsContext()"
returns a valid pointer. If not, you're setup isn't yet complete.

If you still got problems, you might consider presenting some minimal
example that reproduces your problem.

Cheers
Sebastian
Reply all
Reply to author
Forward
0 new messages