[gdal-dev] Problem closing VRT GDALDataset *

Frank Warmerdam warmerdam at pobox.com
Tue Jul 21 15:54:55 EDT 2009


Adeel Raza wrote:
> Hi,
> 
> I 'm using the GDALAutoCreateWarpedVRT() function to warp a MEM 
> GDALDataset. When I use the GDALClose() function to close the source 
> (MEM) dataset nothing happens. However, when I close the warped (VRT) 
> dataset using GDALClose() I get the following error:
> "Unhandled exception at 0x01226b6e in Import Routine Test.exe: 
> 0xC0000005: Access violation writing location 0x238dd369."
> What could be going wrong?

Adeel,

I believe the problem is that the MEM dataset is getting destroyed twice.

GDALAutoCreateWarpedVRT() adds a reference to the passed in dataset to
indicate that something other than the main application code is also using
that dataset.  But the GDALClose() will close it regardless of additional
references.

The safer way is:

     if( GDALDeferenceDataset( hMemDS ) == 0 )
         GDALClose( hMemDS );


In your particular case you know the VRT will hold a reference, so it would
be sufficient for you to drop your reference on the dataset using
GDALDereferenceDataset().

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list