[osg-users] osg2.4 osgUtil::Tessellator bug,cause memory leak
Robert Osfield
robert.osfield at gmail.com
Wed Jul 23 02:00:31 PDT 2008
Hi Heishujing,
If you think you have a bug fix could you please post the whole
modified file to osg-submissions. You can subscribe to the list via:
http://www.openscenegraph.org/projects/osg/wiki/MailingLists
Also have a read through the notes on SubmissionsProtocol so you know
the best way to submit changes for review/merging.
http://www.openscenegraph.org/projects/osg/wiki/MailingLists/SubmissionsProtocol
Also when posting could you provide your full name, as I credit all
contributors in the svn commit messages (this is what the AUTHORS.txt)
comes from.
Thanks,
Robert.
On Wed, Jul 23, 2008 at 2:17 AM, heishuijing_2000
<heishuijing_2000 at 126.com> wrote:
> hi,
> Some days later,i have sent a email which is about this subject,and
> Gordon Tomlinson answered as this:
>
> >This is a compiler problem not an OSG problem, so you really need to ask
> >Microsoft, it's a problem with their compiler and code not OSG
>
> this is my email before:
> >>>hi,
>
> >>>I am sorry to ask about this topic again,:). I have asked the same
> >>>question before. That's about osgMFC example. Somebody in this email
> List
> >>>have help me with it. And that's perfect.
> >>> >>There is a known issue/BUG with MFC, were MFC makes a call to
> >>> >>_CrtDumpMemoryLeaks() in the destructor of the _AFX_DEBUG_STATE,
> followed
> >>> by _CrtSetDbgFlag() which sets it to ~_CRTDBG_LEAK_CHECK_DF
> (therefor
> >>> >>disabling memory leak test at *true* program exit) This
> destructor is
> >>> called at exit (i.e. atexit()), but before statics residing in dlls
> and
> >>> >>others are destroyed, resulting in many false memory leaks are
> reported
>
> >>> I use VS2003 and osg2.4 in debug mode. In my project, i Just add
> >>> mfc71d.lib before all of the osg Libs ,and the VS no longer report
> memory.
>
> >>> Unfortunately,recently the project report memory leak again. That
> is
> >>> about osgUtil::Tessellator,Here is my test code:
> >>> //the test code is drawing a concave like a rect containing a
> triangle with
> >>> it .The Rect and the triangle intersect with one point,as
> >>> //we can see bellow
>
> >>> //an concave polygon
>
> >>> // *******************************
> >>> // * * * *
> >>> // * * * *
> >>> // * * * *
> >>> // * * * *
> >>> // * *********** *
> >>> // * *
> >>> // *******************************
> >>> osgViewer::Viewer viewer;
> >>> osg::ref_ptr< osg::Vec3Array > vertices = new osg::Vec3Array;
> >>> vertices->push_back(osg::Vec3(-100,0,-100));
> >>> vertices->push_back(osg::Vec3(100,0,-100));
> >>> vertices->push_back(osg::Vec3(100,0,100));
> >>> vertices->push_back(osg::Vec3(0,0,100));
> >>> vertices->push_back(osg::Vec3(50,0,50));
> >>> vertices->push_back(osg::Vec3(-50,0,50));
> >>> vertices->push_back(osg::Vec3(0,0,100));
> >>> vertices->push_back(osg::Vec3(-100,0,100));
> >>> osg::ref_ptr< osg::Vec3Array > pNormal = new osg::Vec3Array();
> >>> pNormal->push_back(osg::Vec3(0,-1,0));
> >>> osg::ref_ptr <osg::Geometry> geom = new osg::Geometry;
> >>> geom->setVertexArray(vertices.get());
> >>> geom->setNormalArray(pNormal.get());
> >>> geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
> >>> geom->addPrimitiveSet(new
> >>> osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,vertices->size()));
> >>> osg::ref_ptr< osgUtil::Tessellator > tes = new
> osgUtil::Tessellator();
> >>> tes->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
> >>> tes->setBoundaryOnly(false);
> >>> tes->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD);
> >>> tes->retessellatePolygons(*geom);
>
> >>> osg::ref_ptr<osg::Geode> geode = new osg::Geode;
> >>> geode->addDrawable(geom.get());
> >>> osg::ref_ptr<osg::Group> pGroup = new osg::Group;
> >>> pGroup->addChild(geode.get());
> >>> viewer.setSceneData( pGroup.get() );
>
> >>> I test this code in non-MFC project such as console project,that
> works
> >>> perfect.No memory leak is reported. But when i turn to osg MFC
> project,the
> >>> VS always reports memory leak . I notice that if the polygon is
> >>> self-intersect ,there must be memory leak report in MFC project.
>
> >>> I really do not know how to do about it . I just want to find a
> method to
> >>> prevent the VS reprot false memory leak. Anyone help me? Thank you
> ,:)
>
> Recently i trace this memory leak In VS with osg2.4 osgviewerMFC
> project, i do find the problem.I modify the osg code:
> void Tessellator::reset()
> {
> if (_tobj)
> {
> gluDeleteTess(_tobj);
> _tobj = 0;
> }
> for (Vec3dList::iterator i = _coordData.begin(); i !=
> _coordData.end(); ++i) {
> delete (*i);
> }
> _coordData.clear();
> _newVertexList.clear();
> _primList.clear();
> _errorCode = 0;
> }
> as below:
>
> void Tessellator::reset()
> {
> if (_tobj)
> {
> gluDeleteTess(_tobj);
> _tobj = 0;
> }
> for (Vec3dList::iterator i = _coordData.begin(); i !=
> _coordData.end(); ++i) {
> delete (*i);
> }
> osg::Vec3* vertex = NULL;
> for (NewVertexList::iterator j = _newVertexList.begin(); j !=
> _newVertexList.end(); ++j) {
> NewVertex& newVertex = (*j);
> vertex = newVertex._vpos;
> delete vertex;
> newVertex._vpos = NULL;
> }
> vertex = NULL;
> _coordData.clear();
> _newVertexList.clear();
> _primList.clear();
> _errorCode = 0;
> }
>
> Then the memory leak report disappears,and this does perfect. As
> glu does, osgUtil::Tessalator can draw composite polygon containing concave
> polygon and self-intersecting polygon.
>
>
>
> ________________________________
> 卡卡上网安全助手6.0,震撼上市,绝杀木马!
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
More information about the osg-users
mailing list