Discussion:
[osg-users] Read Image from RTT
RÃŽmulo Cerqueira
2018-09-27 19:07:02 UTC
Permalink
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
Rowley, Marlin R
2018-09-27 19:11:42 UTC
Permalink
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)
***@lmco.com

-----Original Message-----
From: osg-users <osg-users-***@lists.openscenegraph.org> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 2:07 PM
To: osg-***@lists.openscenegraph.org
Subject: EXTERNAL: [osg-users] 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





_______________________________________________
osg-users mailing list
osg-***@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
RÃŽmulo Cerqueira
2018-09-27 19:36:34 UTC
Permalink
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
Rowley, Marlin R
2018-09-27 19:40:54 UTC
Permalink
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)
***@lmco.com

-----Original Message-----
From: osg-users <osg-users-***@lists.openscenegraph.org> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 2:37 PM
To: osg-***@lists.openscenegraph.org
Subject: EXTERNAL: Re: [osg-users] 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





_______________________________________________
osg-users mailing list
osg-***@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
RÃŽmulo Cerqueira
2018-09-27 20:34:15 UTC
Permalink
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
Rowley, Marlin R
2018-09-27 20:38:32 UTC
Permalink
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)
***@lmco.com

-----Original Message-----
From: osg-users <osg-users-***@lists.openscenegraph.org> On Behalf Of Rômulo Cerqueira
Sent: Thursday, September 27, 2018 3:34 PM
To: osg-***@lists.openscenegraph.org
Subject: EXTERNAL: Re: [osg-users] 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





_______________________________________________
osg-users mailing list
osg-***@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Robert Osfield
2018-09-28 06:46:07 UTC
Permalink
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
Post by RÃŽmulo Cerqueira
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?
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();
}
}
#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
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74982#74982
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Loading...