[FWTools] OGRFeature memory problem?
Mike Toothaker
mtoothaker at milcord.com
Mon May 15 09:00:34 EDT 2006
Hello,
I will start off by apologizing for my lack of geospatial knowledge. I have
just started a project and I am trying
to get caught up on the geospatial stuff as quickly as I can while working
with it. We are using gdal in our project
and I have the following code(almost an exact copy paste from the gdal
website).
<code>
OGRRegisterAll();
OGRDataSource *pDS;
pDS = OGRSFDriverRegistrar::Open( "PG:user=postgres password=passwd
dbname=dcmms host=localhost port=5432", TRUE );
if( pDS == NULL )
{
printf( "Open DB failed.\n%s" );
exit( 1 );
}
OGRLayer *poLayer;
poLayer = pDS->CreateLayer( "point_out", NULL, wkbPoint, NULL );
if( poLayer == NULL )
{
printf( "Layer creation failed.\n" );
exit( 1 );
}
OGRFieldDefn oField( "Name", OFTString );
oField.SetWidth(32);
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
printf( "Creating Name field failed.\n" );
exit( 1 );
}
double x = 5.0, y = 50.0;
char szName[] = "Hi There";
OGRFeature *poFeature;
poFeature = new OGRFeature( poLayer->GetLayerDefn() );
poFeature->SetField( "Name", szName );
OGRPoint *poPoint = new OGRPoint();
poPoint->setX( x );
poPoint->setY( y );
poFeature->SetGeometryDirectly( poPoint );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
printf( "Failed to create feature in shapefile.\n" );
exit( 1 );
}
delete poFeature; //<----- Error here
OGRDataSource::DestroyDataSource( pDS );
</code>
I got the dlls from the fwtools 1.3.2 release online. I am using VS C++
2005(I am also new to using 2005, I have been using
6.0 up to the point of working on this project). I get the following error
when delete is called on the OGRFeature object:
"Windows has triggered a breakpoint in GDALConsoleTest.exe. This may be due
to a corruption of the heap, and indicates
a bug in GDALConsoleTest.exe or any of the DLLs it has loaded. Output window
may have more diagnostic information."
Unfortunately my output window has no information. I had thoughts of
looking at the code and possibly figuring out what
the problem is, but when I build gdal from source I can't get it to connect
to my postgres db, which is an entirely different
story all together. I am assuming I must be doing something wrong on my end
because I can't imagine I am the only one
using the OGRFeature class and this seems like a pretty normal thing to do
since it is what is recommended on the gdal
website. If I don't do the delete I get memory leaks. So basically shafted
if I do, shafted if I don't. :-(
Thanks in advance for any help you can give.
Mike
mtoothaker at milcord.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20060515/5c20760e/attachment.html
More information about the FWTools
mailing list