[gdal-dev] GDAL with MFC

Yilmaz Arslanoglu yilmaz.arslanoglu at gmail.com
Mon Oct 26 13:26:35 EDT 2009


Hi all;

Using the GDAL/OGR library, I made a module which extracts the depth points
from the sounding and contour layers of an ENC file.

Everything works perfect if this module is used in a non-MFC project
(btw, projects are compiled with VS 2008) However, when the module is moved
to an MFC-based project, sounding point values (x, y, and z) come as abnormal
values, whereas no problem occurs with the values that come from the
contour layer.

I know that this can possibly originate from different heaps (GDAL dll vs. MFC),
however I wrote the code so that all pointers are created, handled, and finally
destroyed by the GDAL library. Should I not expect a possible heap
corruption problem
here ?

Here, first I insert all features in a vector:

     OGRFeature *poFeature = NULL;
      m_poLayerRef = poDS->GetLayerByName( "SOUNDG" );
      m_poLayerRef->ResetReading();
      std::vector<OGRFeature*> m_features;
      while( (poFeature = m_poLayerRef->GetNextFeature() ) != NULL )
      {
         OGRGeometry *poGeometry = poFeature->GetGeometryRef();
         assert( poGeometry != NULL );

         if ( poGeometry != NULL )
         {
            if ( wkbFlatten(poGeometry->getGeometryType())  == wkbPoint)
            {
               m_features.push_back(poFeature);
            }
            else
               OGRFeature::DestroyFeature(poFeature);
         }
         else
            OGRFeature::DestroyFeature(poFeature);
      }

 Then, I insert all the points to another structure as follows:

  for (std::vector<OGRFeature*>::iterator it = m_features.begin(); it
!= m_features.end(); it++)
   {
      poFeature = (*it);

      poGeometry = poFeature->GetGeometryRef();
      assert( (poGeometry != NULL) && (
wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ) );
      if ( (poGeometry != NULL) && (
wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ) )
      {
         x = ( ((OGRPoint *)poGeometry)->getX() );
         y = ( ((OGRPoint *)poGeometry)->getY() );
         z = ( ((OGRPoint *)poGeometry)->getZ() );

         depthMap.Insert( x, y, z );
      }
   }


As another question, I do the following simple operation (again in MFC):

     OGRSpatialReference *poSRS = new OGRSpatialReference;
     OGRSpatialReference::DestroySpatialReference(poSRS);

and I get heap corruption error. Do we have another way to create a
spatial reference system object for this purpose?

Best regards,
Yilmaz


More information about the gdal-dev mailing list