[Gdal-dev] Free OGRGeometry?

Craig Miller craig.miller at spatialminds.com
Thu Dec 1 20:51:39 EST 2005


I thought I'd have a conversation with myself here...   :-)

After defining /MDd for GDAL I am getting assertions about improper use of
the heap.  These problems appear with both my application, and with the gdal
utilities (gdalinfo).  Is there a workaround that will allow me to create a
debug build of gdal that is compatible with my application's debug build?
The reason the asserts don't occur when /MD is used is because they are only
present with the debug builds of the system libraries.  I am not positive,
but believe the ASSERTS are triggering valid heap allocation problems inside
GDAL though.


I'd like to build with the following options in order to be compatible with
my application debug settings.
OPTFLAGS=	/nologo /MDd /GX /Zi /Fd$(GDAL_ROOT)\gdal.pdb

Thanks,
Craig

Fore quick reference, here is the definition of the /MDd flag and the /MD
flag

/MDd Defines _DEBUG, _MT, and _DLL so that debug multithread- and
DLL-specific versions of the run-time routines are selected from the
standard .h files. It also causes the compiler to place the library name
MSVCRTD.lib into the .obj file.  

/MD Defines _MT and _DLL so that both multithread- and DLL-specific versions
of the run-time routines are selected from the standard .h files. This
option also causes the compiler to place the library name MSVCRT.lib into
the .obj file. 
Applications compiled with this option are statically linked to MSVCRT.lib.
This library provides a layer of code that allows the linker to resolve
external references. The actual working code is contained in MSVCR71.DLL,
which must be available at run time to applications linked with MSVCRT.lib.

When /MD is used with _STATIC_CPPLIB defined (/D_STATIC_CPPLIB) it will
cause the application to link with the static multithread Standard C++
Library (libcpmt.lib) instead of the dynamic version (msvcprt.lib) while
still dynamically linking to the main CRT via msvcrt.lib.
 

-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Craig Miller
Sent: Thursday, December 01, 2005 4:28 PM
To: 'Gdal-Dev'
Subject: RE: [Gdal-dev] Free OGRGeometry?

I looked at this a little closer.  You are right, gdal was built with /MD
and my app was in debug mode using /MDd.  I actually have 2 builds of gdal
Release/Debug and forgot to set the /MD flag to /MDd when I did my debug
build.

Good catch.

--Craig
 

-----Original Message-----
From: fwarmerdam at gmail.com [mailto:fwarmerdam at gmail.com] On Behalf Of Frank
Warmerdam
Sent: Friday, November 25, 2005 1:00 PM
To: Craig Miller
Subject: Re: [Gdal-dev] Free OGRGeometry?

On 11/25/05, Craig Miller <craig.miller at spatialminds.com> wrote:
> I should have mentioned that using delete (under windows) is causing 
> an unhandled exception.  I thought that there might be a special CPL* 
> routine that has to be used to prevent this from happening.
>
> I'm using a rect now, but in the future I hope to allow other 
> geometric elements to be used to filter the geometry (like an 
> ecological region, county, etc).

Craig,

I imagine your mainline is not build with /MD, but GDAL13.DLL is.
In that case GDAL uses the MSVCRT heap but your application uses its own
private heap. This can result in all sorts of problems.

Since you did the "new OGRPolygon" in your own code, I would have thought
doing the delete there would also be ok, but perhaps not.

There is also an OGRGeometryFactory::destroyGeometry( OGRGeometry *) method
you can use to destroy a geometry within the GDAL DLL.  This is often useful
if you need to destroy a geometry created by GDAL.

Of course, your exception could be due to some other heap corruption issue.
It is hard to know.

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


_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev





More information about the Gdal-dev mailing list