梁天辰, I am guessing you are working on Windows and are running into problems with a mix of runtime heaps. I would suggest avoiding using new and delete directly and instead leaving everything to functions from the GDAL DLL.
I believe you should use OGRGeometryFactory::createGeometry(wkbLinearRing) to create the linear ring (use wkbPolygon for the polygon) and OGRGeometryFactory::destroyGeometry() to destroy geometries. Keep in mind that addRingDirectly() transfers ownership of the ring to the polygon so you should not destroy the ring after that. It will be cleaned up by the polygon when that is destroyed. Best regards, Frank On Mon, May 13, 2013 at 6:47 PM, 梁天辰 <[email protected]> wrote: > Hello all > > The following function uses c++ operator new to get a pointer of > OGRLinearRing and modified that ring. Before the function returns, it's > neccessary to delete that pointer,but "delete poFLinear;" will cause a > runtime error and the program stops running. What should I do to delete > that pointer? Thanks. > > > int GetWSInfo(const vector<Point> &ring,OUT CWSInfo & wsinfo) > { > OGRLinearRing *poFLinear = new OGRLinearRing(); > poFLinear->setPoints(ring.size(),(OGRRawPoint*)(&ring[0])); > poFLinear->closeRings(); > OGRPolygon * poFPoly = new OGRPolygon(); > poFPoly->addRingDirectly(poFLinear); > wsinfo.WSAREA = poFLinear->get_Area(); > wsinfo.WSPERI = poFLinear->get_Length(); > //delete poFLinear; > //delete poFPoly; > return RETURN_OK; > } > > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev > -- ---------------------------------------+-------------------------------------- I set the clouds in motion - turn up | Frank Warmerdam, [email protected] light and sound - activate the windows | http://pobox.com/~warmerdam and watch the world go round - Rush | Geospatial Software Developer
_______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
