[Gdal-dev] Crash in VC++ in GDALClose(VRTDataset*)

Steve Brooks sbrooks2 at kc.rr.com
Tue Mar 25 22:50:56 EST 2003


Garvan,

 To use the same heaps in GDAL and Visual C++, I have edited nmake.opt

For debug mode OPTFLAGS is

OPTFLAGS= /MDd /W3 /Gm /GX /ZI /Od /D "_MBCS" /D "WIN32" /D "_DEBUG"
/Fd$(GDAL_ROOT)\gdal.pdb

For release mode OPTFLAGS is 

OPTFLAGS=	/MD /W3 /GX /Zi /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"
/D "_MBCS" 

The important switchs are /MDd and /MD.

Perform a full rebuild on GDAL with debug and release.

Then in your application make sure on the Project property pages you are
using 
the Code Generation Settings for the Runtime library as

Multi-threaded Debug DLL (/MDd) for Debug
Multi-threaded DLL (/MD) for Release

Also, if you are using a binary release of GDAL instead of rebuilding
it,
you maybe running into different heaps from different compiler versions
between GDAL and the your Project.  It would be better to build it
yourself.

You don't have to use the Multi-threaded DLL Runtime libraries, but you
do need to use the sameone as in GDAL as your Project if you are going
to be
Allocating memory in one and freeing it in the other.

Hope this helps.

Steve Brooks.



-----Original Message-----
From: gdal-dev-admin at remotesensing.org
[mailto:gdal-dev-admin at remotesensing.org] On Behalf Of Frank Warmerdam
Sent: Tuesday, March 25, 2003 2:38 PM
To: gdal-dev at remotesensing.org
Subject: Re: [Gdal-dev] Crash in VC++ in GDALClose(VRTDataset*)


Garvan Keeley wrote:
> Hi,
> I am trying to use some of the code from gdal_translate, but I found 
> it was crashing when built under Visual Studio .Net (unmanaged C++).
> 
> Here is a small C++ console app that crashes in the function 
> GDALClose(). Any idea what might be causing this?
> 
> 
> // assume library paths and linker options are set correctly // i.e. 
> add the gdal source tree to additional include dirs and // gdal_i.lib 
> added to linker dependencies
> 
> #include "gdal.h"
> #include "frmts\vrt\vrtdataset.h"
> 
> int _tmain(int argc, _TCHAR* argv[])
> {
> 	VRTDataset* poVDS = new VRTDataset( 100, 100 );
> 	GDALClose( (GDALDatasetH) poVDS );


Garvan,

I have tried this on Linux under valgrind and it is fine.  I presume the
problem is that you are allocating the VRTDataset in your main, which
will use one "heap".  Then you free it in GDALClose() which uses the
heap assigned to the GDAL11.DLL.

I would suggest instead that you change "GDALClose((GDALDatasetH) poVDS
);" to "delete poVDS;".

Note, there are ways to build GDAL and your main application so they
both use the C runtime library for allocations and deallocations
(effectively operating against the same heap) but I don't know the
details of how that is accomplished.  Perhaps others could comment.

I have had lots of problems in the past with mixing new/delete calls
between mainlines and the GDAL library.  A more common case is where an
object is allocated in the library and then destroyed with "delete" in
the mainline.

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 remotesensing.org
http://remotesensing.org/mailman/listinfo/gdal-dev





More information about the Gdal-dev mailing list