[Gdal-dev] OGRSpatialReference: delete/Dereference crashes under MS Visual Studio (GDAL 1.3.1)

Frank Warmerdam warmerdam at pobox.com
Thu Mar 9 09:39:45 EST 2006


Pieter Bekaert wrote:
> While porting some code to Visual Studio, the following problem has
> occurred:
> 
> Deleting (or dereferencing when the counter == 1) in our setup causes an
> exception to be thrown. This happens even with the following trivial
> piece of code:
> ...
> {
> 	OGRSpatialReference* ogrsr = new OGRSpatialReference();
> 	delete ogrsr;
> }
> 
> I searched the bug list but didn't find anything relevant.
> 
> We started from gdal131.zip and tried it with Visual Studio 2003.
> 
> Any suggestions?

Pieter,

Do you know if you are using the same heap for your application code,
and OGR in this case?  For instance, are both compiled with /MD to
us MSVCRT.DLL (or modern equivelent)?

If not, then I suspect the problem relates to cross-heap issues.  The
solution would either be to use the C API instead of the C++ API or
to use alternate methods to create and destroy at least.

eg.
	OGRSpatialReference *ogrsrs = (OGRSpatialReference *)
                         OSRNewSpatialReference( NULL );

         ...

         OGRDestroySpatialReference( ogrsrs );

I realize it doesn't help anything, but at this point I would also
like to say that it is a *great* frustration to me that Microsoft
continues to propagate this whole "heap per DLL" paradyme which makes
it very hard to port C++ libraries from platforms compliant with the
C++ language standard.

I try to be platform agnostic, but windows consistently makes my life
a misery!

/me breathes deeply, and steps off the soapbox.

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    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list