Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#2944 closed defect (wontfix)

Custom Plugin crash with OSGEO4W GDAL's version, alignement problems?

Reported by: nass Owned by: warmerdam
Priority: normal Milestone:
Component: GDAL_Raster Version: 1.5.4
Severity: blocker Keywords: plugin
Cc:

Description

Hi, I am encoutering a weird problem,with a plugin that I am developing for GDAL. Compilation is OK,but when I try my plugin,GDAL crashes.I used a debugger,and discovered that it seems that there is an alignement problem between GDalDriver taken from gdal_priv,and the one used for compiling GDAL.Maybe this is because I compiled the code with VC6 and VC8,and not with VC71 (that is the version used for OSGEO4W's GDAL version)?!

Here is a sample code that illustrate my problem,please report to the comments :

void GDALRegister_packed()
{

    GDALDriver  *poDriver;

    if( GDALGetDriverByName( PACKED_DRIVER_NAME ) == NULL )
    {
        poDriver = new GDALDriver();
        
        poDriver->SetDescription( PACKED_DRIVER_NAME );
        poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,PACKED_DRIVER_DESC );

        poDriver->pfnOpen = PackedDataset::Open;

//At this point poDriver members are ok
//When the code goes trought RegisterDriver, members of poDriver are not correct //anymore (pfnOpen is NULL and pfnCreate contains the address of pfnOpen.
//As pfnOpen is called after,GDAL crash as it is NULL.

        GetGDALDriverManager()->RegisterDriver( poDriver );
    }
}
GDALDataset* PackedDataset::Open( GDALOpenInfo * poOpenInfo)
{
 return NULL; //For test purpose only
}

Thank you in advance, Best regards. Nassim.

Change History (4)

comment:1 by nass, 15 years ago

Component: defaultGDAL_Raster
Version: unspecified1.5.4

comment:2 by nass, 15 years ago

PS : I successfully compiled & used my plugin with another version of GDAL.

comment:3 by warmerdam, 15 years ago

Keywords: plugin added
Resolution: wontfix
Status: newclosed

I imagine the problem is that you are linking with a different runtime library. It has been my experience that this results in heap corruption when the GDAL DLL invokes delete on dataset or driver objects instantiated with new in a plugin linked against a distinct runtime (and hence a distinct heap).

I have been contemplating possible changes to how plugins destroy things to possibly resolve this but I have not come up with a plan yet. In the meantime, it is pretty much necessary to compile OSGeo4W GDAL plugins with MSVC 7.1 to match how GDAL is built.

Assuming my analysis is correct, I'm marking this ticket WONTFIX mainly because I can't fix it.

comment:4 by nass, 15 years ago

Hi, thank you for your answer. I will try to compile my plugin using VC71 I will keep you in touch. Even if I understand that different runtimes can cause alloc/unalloc problems,I still don't understand why the alignement changes (If the headers are the same...).

Anyway,VC71 is quite deprecated,and it sould be a good idea that OSGEO4W delivers products that are compiled with an available VC express edition (VC71 express is not availabe,even if there is something called VC toolkit 2003,but it is too basic,and not officialy available).

Regards.

Note: See TracTickets for help on using tickets.