[gdal-dev] Problem closing VRT GDALDataset *

Adeel Raza adeel.raza at crc.gc.ca
Tue Jul 21 16:13:53 EDT 2009


Hi Frank,

Thanks for the help. It seems like you were correct. When I dereference 
the MEM dataset the post-decrement reference count is not 0. My question 
is: do I not close the MEM dataset since its reference count is not 0?

Best Regards,
Adeel Raza.

Frank Warmerdam wrote:
> 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,



More information about the gdal-dev mailing list