[Gdal-dev] OGR:GetNextFeature() throws exception in WINXP

Mateusz Łoskot mateusz at loskot.net
Mon Mar 20 07:30:23 EST 2006


Vidhiyadharan Nadarajah wrote:
> Hi,
> 
> Iam a begineer in this field. I have been using OGR for the past 6 months.
> I have built a windows application (using VC++) which is runing perfectly
> fine in WIN2K.
> I have built this application based on the sample provided in the OGR
> Tutorial (http://gdal.maptools.org/ogr/ogr_apitut.html). Reading a point
> layer is alone described in the tutorial and i have added some code for
> reading the polygon layer.
> My problem is the same application crashes in WinXP. The function
> "poLayer->GetNextFeature()" throws an exception in winXP.Iam unable to find
> the exact exception.
> 
> I have compiled GDAL1.3.0 and PROJ4 and linking the DLL in my application.
> Please find below the piece of code that Iam using. Please help me to find
> out the mistake that Iam doing. I can also send the VC++ workspace and the
> shape file, if it is needed for finding out the problem.
> 
> 
> #include "stdafx.h"
> #include "ogrsf_frmts.h"
> 
> int main()
> {
> 
>     OGRRegisterAll();
>     OGRDataSource       *poDS;
>     poDS = OGRSFDriverRegistrar::Open( "C:\ind.shp", FALSE );
>     if( poDS == NULL )
>     {
>         printf( "Open failed.\n%s" );
>         exit( 1 );
>     }
> 
>     OGRLayer  *poLayer;
>     poLayer = poDS->GetLayerByName( "india_ds" );
^^^^^^^^^^^^^^^^^^^^^^^^^

I'd supose here you are getting null pointer.
Add simple test if poLayer is a null pointer:

     if (NULL == poLayer)
     {
         printf("Layer not found\n");
         OGRDataSource::DestroyDataSource(poDS);
         return -1;
     }

And you will see if this is a problem.

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list