OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Read Image from RTT


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 65
Location: Brazil

PostPosted: Thu Sep 27, 2018 7:06 pm    Post subject:
Read Image from RTT
Reply with quote

Hi,

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?


Code:
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
    _condition->wait(_mutex);

    return _image;
}

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

    if (gfxc->getTraits()) {
        _mutex->lock();

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

        // THE PROGRAM CRASHES HERE
        _image->readImageFromCurrentTexture(renderInfo.getContextID(), true, GL_FLOAT);

        // grants the access to image
        _condition->signal();
        _mutex->unlock();
    }
}


Output from GDB:

Code:
#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,

Cheers,
Rômulo
Back to top
View user's profile Send private message
Rowley, Marlin R
Guest





PostPosted: Thu Sep 27, 2018 7:11 pm    Post subject:
EXTERNAL: Read Image from RTT
Reply with quote

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)


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

Hi,

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?



Code:
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
_condition->wait(_mutex);

return _image;
}

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

if (gfxc->getTraits()) {
_mutex->lock();

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

// THE PROGRAM CRASHES HERE
_image->readImageFromCurrentTexture(renderInfo.getContextID(), true, GL_FLOAT);

// grants the access to image
_condition->signal();
_mutex->unlock();
}
}




Output from GDB:


Code:
#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,

Cheers,
Rômulo

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








------------------
Post generated by Mail2Forum
Back to top
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 65
Location: Brazil

PostPosted: Thu Sep 27, 2018 7:36 pm    Post subject:
Reply with quote

Hi Martin,

I never faced with this problem (gfxc->getTraits() == NULL). Do you have some tip to solve it?
...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
Rowley, Marlin R
Guest





PostPosted: Thu Sep 27, 2018 7:41 pm    Post subject:
EXTERNAL: Re: Read Image from RTT
Reply with quote

I just noticed that. You'll have to check and see what line it's crashing on in the debugger. I just noticed that you get a graphics context but never check to see if it's NULL. A NULL pointer can't access any methods of the class it's referring to.

Good Luck!

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)


-----Original Message-----
From: osg-users <> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 2:37 PM
To:
Subject: EXTERNAL: Re: Read Image from RTT

Hi Martin,

I never faced with this problem. Do you have some tip to solve it?
...

Thank you!

Cheers,
Rômulo

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








------------------
Post generated by Mail2Forum
Back to top
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 65
Location: Brazil

PostPosted: Thu Sep 27, 2018 8:34 pm    Post subject:
Reply with quote

Solved the problem!

Perhaps readImageFromCurentTexture() works only with osg::ref_ptr<osg::Image> instead of osg::Image*.
...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
Rowley, Marlin R
Guest





PostPosted: Thu Sep 27, 2018 8:38 pm    Post subject:
EXTERNAL: Re: Read Image from RTT
Reply with quote

Did you allocate storage for your osg::Image* before using it (i.e. osg::Image* img = new osg::Image)? That doesn't make sense why it would only work on a osg::ref_ptr.

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)


-----Original Message-----
From: osg-users <> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 3:34 PM
To:
Subject: EXTERNAL: Re: Read Image from RTT

Solved the problem!

Perhaps readImageFromCurentTexture() works only with osg::ref_ptr<osg::Image> instead of osg::Image*.
...

Thank you!

Cheers,
Rômulo

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








------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12145

PostPosted: Fri Sep 28, 2018 6:46 am    Post subject:
Read Image from RTT
Reply with quote

Hi Rômulo,

Without the the line numbers on the source we can't match up the stack
trace crash point to lines of code.

Robert.
On Thu, 27 Sep 2018 at 20:45, Rômulo Cerqueira
<> wrote:
Quote:

Hi,

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?



Code:
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
_condition->wait(_mutex);

return _image;
}

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

if (gfxc->getTraits()) {
_mutex->lock();

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

// THE PROGRAM CRASHES HERE
_image->readImageFromCurrentTexture(renderInfo.getContextID(), true, GL_FLOAT);

// grants the access to image
_condition->signal();
_mutex->unlock();
}
}




Output from GDB:


Code:
#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,

Cheers,
Rômulo

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Change color of node read from dxf file dhhabyc General 1 Sat Nov 17, 2018 12:58 pm View latest post
No new posts Missing 'png' image reader sdef General [3rdparty] 2 Mon Nov 12, 2018 5:51 am View latest post
No new posts Image containing floats ivar General 2 Thu Sep 20, 2018 9:18 am View latest post
No new posts minor change: move assumeSizedInterna... mp3butcher General 9 Wed Aug 15, 2018 10:07 pm View latest post
No new posts Load OSG trimesh to ODE: Read Vertice... TKoller General 2 Fri Jul 20, 2018 3:06 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP