[osg-users] EXTERNAL: Read Image from RTT

Rowley, Marlin R marlin.r.rowley at lmco.com
Thu Sep 27 12:11:42 PDT 2018

What if your gfxc returns NULL?  You assume that gfxc->getTraits() should always have a valid reference pointer.

Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
marlin.r.rowley at lmco.com

-----Original Message-----
From: osg-users <osg-users-bounces at lists.openscenegraph.org> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 2:07 PM
To: osg-users at lists.openscenegraph.org
Subject: EXTERNAL: [osg-users] Read Image from RTT


I have tried to read image from RTT (where the image is "not attached", but available on buffer) using a osg::Camera::DrawCallback, the compilation is working, however the executable brings me a segmentation fault during image rendering. How can I solve this?

WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr<osg::GraphicsContext> gfxc, osg::Texture2D* tex) {
    _mutex = new OpenThreads::Mutex();
    _condition = new OpenThreads::Condition();
    _image = new osg::Image();

    // checks the GraficContext from the camera viewer
    if (gfxc->getTraits()) {
        _tex = tex;
        int width = gfxc->getTraits()->width;
        int height = gfxc->getTraits()->height;
        _image->allocateImage(width, height, 1, GL_RGBA, GL_FLOAT);

WindowCaptureScreen::~WindowCaptureScreen() {
    delete (_condition);
    delete (_mutex);

osg::ref_ptr<osg::Image> WindowCaptureScreen::captureImage() {
    //wait to finish the capture image in call back

    return _image;

void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
    osg::ref_ptr<osg::GraphicsContext> gfxc = renderInfo.getState()->getGraphicsContext();

    if (gfxc->getTraits()) {

        // read the color buffer as 32-bit floating point
        renderInfo.getState()->applyTextureAttribute(0, _tex);

        _image->readImageFromCurrentTexture(renderInfo.getContextID(), true, GL_FLOAT);

        // grants the access to image

Output from GDB:

#0  0xffffffffffffff88 in ?? ()
#1  0x00007fffef1ee39d in normal_depth_map::WindowCaptureScreen::operator() (this=0x7fffb53ee7a0, renderInfo=...)
    at /home/romulo/dev/sonarsim/simulation/normal_depth_map/src/ImageViewerCaptureTool.cpp:158
#2  0x00007fffebb43b10 in osgUtil::RenderStage::draw(osg::RenderInfo&, osgUtil::RenderLeaf*&) ()
   from target:/usr/lib/x86_64-linux-gnu/libosgUtil.so.100
#3  0x00007fffebb4bdb7 in osgUtil::SceneView::draw() () from target:/usr/lib/x86_64-linux-gnu/libosgUtil.so.100
#4  0x00007fffec31c03f in osgViewer::Renderer::draw() () from target:/usr/lib/x86_64-linux-gnu/libosgViewer.so.100
#5  0x00007fffef557d49 in osg::GraphicsContext::runOperations() ()
   from target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#6  0x00007fffef5a7bbf in osg::OperationThread::run() () from target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#7  0x00007fffef5596f8 in osg::GraphicsThread::run() () from target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#8  0x00007fffecbd06c8 in OpenThreads::ThreadPrivateActions::StartThread(void*) ()
   from target:/usr/lib/x86_64-linux-gnu/libOpenThreads.so.20
#9  0x00007ffff60246ba in start_thread (arg=0x7fffa7efe700) at pthread_create.c:333
#10 0x00007ffff130f41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thanks in advance,


Read this topic online here:

osg-users mailing list
osg-users at lists.openscenegraph.org

More information about the osg-users mailing list