Hello.
I have a file with a series of points. I'm trying to trace a line adding these 
points in different moments (calling the method "addPointToLine(Pnt3f point)"). 
If I add some points in the constructor (and only there), the line is drawn. If 
I add the points in another method, I can't understand why my code doesn't 
work... 


//I USE THESE PROPERTIES:

        GeometryPtr  mGeometricData;
        NodePtr mGeometricNode;
        GeoPLengthsPtr mLengths;
        GeoPositions3fPtr mPositions;
        GeoIndicesUI32Ptr mIndices;
        int mNumPoints;


//THIS IS PART OF THE 
CONSTRUCTOR:*******************************************************************************************************
//...

                mGeometricNode = Node::create();

                if (mGeometricNode == NullFC) {
                        throw DllException::createDllException("ERROR: cannot 
create geometry core");
                }
                
                //Create  a geometry core
                mGeometricData = Geometry::create();

                if (mGeometricData == NullFC) {
                        throw DllException::createDllException("ERROR: cannot 
create geometry core");
                }
                
                //set the geometric core
                beginEditCP(mGeometricNode, Node::CoreFieldMask);
                        mGeometricNode->setCore(mGeometricData);
                endEditCP(mGeometricNode, Node::CoreFieldMask);

                //Now we must fill the geometry 
                //Here we define the type of primitive we will use
                GeoPTypesPtr type = GeoPTypesUI8::create();
                beginEditCP(type,GeoPTypesUI8::GeoPropDataFieldMask);
                        type->addValue(GL_LINES);
                endEditCP(type,GeoPTypesUI8::GeoPropDataFieldMask);

                //Here we set the total number of vertices to be drawn
                mLengths = GeoPLengthsUI32::create();
                //Create the list of vertices
                mPositions = GeoPositions3f::create();
                //Create list of indices
                mIndices = GeoIndicesUI32::create();

                //Now we fill the geometric core with all this stuff
                beginEditCP(mGeometricData, Geometry::TypesFieldMask 
                                                                | 
Geometry::LengthsFieldMask
                                                                | 
Geometry::PositionsFieldMask
                                                                | 
Geometry::IndicesFieldMask
                                                                | 
Geometry::MaterialFieldMask);

                        mGeometricData->setTypes(type);
                        mGeometricData->setLengths(mLengths);
                        mGeometricData->setPositions(mPositions);
                        mGeometricData->setIndices(mIndices);
                        mGeometricData->setMaterial(getDefaultMaterial());
                        
                endEditCP(mGeometricData, Geometry::TypesFieldMask 
                                                                | 
Geometry::LengthsFieldMask
                                                                | 
Geometry::PositionsFieldMask
                                                                | 
Geometry::IndicesFieldMask
                                                                | 
Geometry::MaterialFieldMask);


                //disable rendering till we have at least 2 points
                beginEditCP(mGeometricNode);
                        mGeometricNode->setActive(false);
                endEditCP(mGeometricNode);

                //no points at first
                mNumPoints=0;
//...


//THIS IS THE METHOD CALLED TO ADD A POINT TO THE 
LINE************************************************************************************

addPointToLine(Pnt3f point)
{
        //Increase num of points
        mNumPoints++;
        
        //Update size
        beginEditCP(mLengths, GeoPLengthsUI32::GeoPropDataFieldMask);
        if (mNumPoints > 1) 
        {
                mLengths->setValue((mNumPoints-1)*2,0);
        }
        else 
        {
                mLengths->addValue((mNumPoints-1)*2);
        }
        endEditCP(mLengths, GeoPLengthsUI32::GeoPropDataFieldMask);

        //Add given point to vertices
        beginEditCP(mPositions, GeoPositions3f::GeoPropDataFieldMask);
                mPositions->addValue(point);
        endEditCP(mPositions, GeoPositions3f::GeoPropDataFieldMask);
        
        //check if we have at least two points
        if (mNumPoints > 1)
        {
                beginEditCP(mIndices, GeoIndicesUI32::GeoPropDataFieldMask);
                        mIndices->addValue(mNumPoints-2);
                        mIndices->addValue(mNumPoints-1);
                endEditCP(mIndices, GeoIndicesUI32::GeoPropDataFieldMask);

                //set the node active
                beginEditCP(mGeometricNode);
                        mGeometricNode->setActive(true);
                endEditCP(mGeometricNode);

        }
}


Every time I call "mLengths->setValue((mNumPoints-1)*2,0);" the application 
crashes with a memory error.
It seems that mLengths points to NULL...

Could anyone help me?
Thanks,
Antonio


___________________________________________________________________
Dimagrire in 30 giorni con New Giorno & Notte! Garanzia 100% Soddisfatti o 
Rimborsati! 
http://click.libero.it/diete



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to