Any ideas why the class from the code below would cause memory leaks?
I've read as many tutorials as i could find, to learn the proper use of
the osg::ref_ptr, and i tried all the tricks up my sleeve. However I'm
still getting a memory leak in the member variable m_Text;
Thanks in advance.
Tamer ElNashar
VRSonic Inc.
////////////////////////////////////
//GLTextString.h
///////////////////////////////////
class GLTextString : pblic osg::Geode
{
private:
osg::ref_ptr<osgText::Text> m_Text;
public:
static osg::Vec4 m_Color;
static osg::Vec4 m_BackdropColor;
GLTextString(std::string str, float fontSize = 20.0f, std::string
font = "fonts/tahoma.ttf");
protected:
virtual ~GLTextString();
public:
osg::ref_ptr<osgText::Text> GetText(void) { return m_Text; }
void SetText(string text) { m_Text->setText(text); }
};
////////////////////////////////////
//GLTextString.cpp
///////////////////////////////////
osg::Vec4 GLTextString::m_Color = osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f);
osg::Vec4 GLTextString::m_BackdropColor = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
GLTextString::GLTextString(std::string str, float fontSize, string font)
{
osg::Vec3 pos(0, 0, -.5 );
m_Text = new osgText::Text;
m_Text->setColor(m_Color);
m_Text->setFont("fonts/tahoma.ttf");
m_Text->setCharacterSize(fontSize);
m_Text->setPosition(pos);
m_Text->setAxisAlignment(osgText::Text::SCREEN);
m_Text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
m_Text->setBackdropColor(m_BackdropColor);
if (!str.empty())
m_Text->setText(str);
addDrawable(m_Text.get());
// turn lighting off for the text and disable depth test to ensure
its always ontop.
osg::StateSet* stateset = getOrCreateStateSet();
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
// Disable depth test, and make sure that the string is drawn after
everything
// else so that it always appears on top.
stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
setStateSet(stateset);
}
GLTextString::~GLTextString()
{
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org