Opened 19 years ago

Last modified 19 years ago

#895 closed defect (fixed)

GetGeomType fails in debug environment for PostGIS provider

Reported by: craig.miller@… Owned by: warmerdam
Priority: high Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc:

Description

OGRLayer->GetLayerDefn()->GetGeomType() against a PostGIS provider always
returns wkbUnknown when a dynamically linked application runs under the Visual
C++ 7 debugger.  The same call succeeds with either a debug or release build
when it is run outside of the debugger.

gdal/ogr is compiled with PostGIS and GEOS support.
PostgreSQL version 8.0.3
PostGIS version 1.0.0.1

Change History (5)

comment:1 by warmerdam, 19 years ago

Craig, 

There were some changes in this area recently.  Is there any chance
you were using different versions of the GDAL DLL when in the debugger
as opposed to free standing? 

The code that determines the geometry type is in ogrpgtablelayer.cpp and looks
like this:
    // get layer geometry type (for PostGIS dataset)
    if ( bHasPostGISGeometry )
    {
        sprintf(szCommand,
                "SELECT type, coord_dimension FROM geometry_columns WHERE
f_table_name='%s'", 
                pszTable);

        hResult = PQexec(hPGConn,szCommand);
        if ( hResult && PQntuples(hResult) == 1 && !PQgetisnull(hResult,0,0) )
        {
            char * pszType = PQgetvalue(hResult,0,0);
            OGRwkbGeometryType nGeomType = wkbUnknown;

            nCoordDimension = MAX(2,MIN(3,atoi(PQgetvalue(hResult,0,1))));

            // check only standard OGC geometry types
            if ( EQUAL(pszType, "POINT") )
                nGeomType = wkbPoint;
            else if ( EQUAL(pszType,"LINESTRING"))
                nGeomType = wkbLineString;
            else if ( EQUAL(pszType,"POLYGON"))
                nGeomType = wkbPolygon;
            else if ( EQUAL(pszType,"MULTIPOINT"))
                nGeomType = wkbMultiPoint;
            else if ( EQUAL(pszType,"MULTILINESTRING"))
                nGeomType = wkbMultiLineString;
            else if ( EQUAL(pszType,"MULTIPOLYGON"))
                nGeomType = wkbMultiPolygon;
            else if ( EQUAL(pszType,"GEOMETRYCOLLECTION"))
                nGeomType = wkbGeometryCollection;

            if( nCoordDimension == 3 && nGeomType != wkbUnknown )
                nGeomType = (OGRwkbGeometryType) (nGeomType | wkb25DBit);

            CPLDebug("OGR_PG","Layer '%s' geometry type: %s:%s, Dim=%d", 
                     pszTable, pszType, OGRGeometryTypeToName(nGeomType),
                     nCoordDimension );

            poDefn->SetGeomType( nGeomType );

            PQclear( hResult );
        }
    }

Would it be possible for you to step through it in the debugger to see
what is happening?  Note, I made some substantial changes in the above
code just last night, so you should ensure you have the latest code before
pursuing the issue in the debugger. 

I don't have a PostGIS instance on windows currently, and I am not
confident I could reproduce the problem if I did.  But if you can't
find out anything interesting, I could try to reproduce it here somehow.

comment:2 by craig.miller@…, 19 years ago

I'm pretty sure I was using the correct DLL.  I used process explorer to verify
that the correct DLL is being loaded (it shows the full path).  I can repeat the
bug inside of the developer studio gui menu by switching between F5
(Debug->Start) or Ctrl-F5 (Debug->Start without Debugging).  I have both Debug
and Release builds of GDAL, but I've verified that the bug only shows up when
running under the Debugger regardless of whether it is a Debug/Release build of
GDAL.

My personal hypothesis at the moment is that it is actually a libpq bug, but I
haven't had a chance to put the GDAL code under the debugger to see exactly
where the bug first appears.  I looked at the ogrpgtablelayer.cpp code last week
before vacation, and it looked good to me (it works outside of the debugger
after all :-D ).   I'll get the latest GDAL code and see if it dissapears.  If
not, I'll put that code under the debugger.  Either way, I'll update the defect
comments when I'm finished.

comment:3 by warmerdam, 19 years ago

Craig, 

Sounds good.

Thanks

comment:4 by craig.miller@…, 19 years ago

The daily July 21, 2005 snapshot works.  :-)

--Craig

comment:5 by warmerdam, 19 years ago

Craig, 

Ah, ok.  I'll close this for now, but if the problem recurs with recent
code please reopen it. 

Note: See TracTickets for help on using tickets.