[osg-users] Read Image from RTT
Rômulo Cerqueira
romulogcerqueira at gmail.com
Thu Sep 27 12:07:02 PDT 2018
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
More information about the osg-users
mailing list