[gdal-dev] Access violation OGRSpatialReference.importFromESRI() in GDAL304.dll

Even Rouault even.rouault at spatialys.com
Fri Feb 4 07:56:20 PST 2022


RTF(antastic)M :-)

==> 
https://gdal.org/doxygen/classOGRSpatialReference.html#af91af2639702e2793daf93ffe231b577 
:

Parameters
    papszPrj 	NULL terminated list of strings containing the definition.

So change your code to something like:

   char apszPrj[2];
   char* s = proj.GetBuffer();
   apszPrj[0] = s;
   apszPrj[1] = NULL;
   return sr->importFromWkt(apszPrj);

Le 04/02/2022 à 16:47, Paul Meems a écrit :
> Hi List,
>
> We use GDAL v3+ in our Open Source mapping application MapWinGIS.
> We build using VS2019 on Windows and we use the files from GisInternals.
>
> We have a GeoProjection class which in turn calls 
> some/most OGRSpatialReference methods.
> When calling OGRSpatialReference.importFromESRI() compiled for Win32 
> we have no issues.
> When calling the same code compiled for Win64 we get this exception:
> Exception thrown at 0x00007FFD93074839 (gdal304.dll) 0xC0000005: 
> Access violation reading location 0xFFFFFFFFFFFFFFFF
>
> We also implement the very similar method importFromWkt(). This method 
> has no issues on Win32 or Win64.
>
> Here's some relevant code from GeoProjection.cpp:
> STDMETHODIMP CGeoProjection::ImportFromESRI(const BSTR proj, 
> VARIANT_BOOL* retVal)
> {
>   AFX_MANAGE_STATE(AfxGetStaticModuleState())
>   USES_CONVERSION;
>
>   const CString s = OLE2A(proj);
>   const OGRErr err = ProjectionHelper::ImportFromEsri(_projection, s);
>
>   *retVal = err == OGRERR_NONE ? VARIANT_TRUE : VARIANT_FALSE;
>   if (err != OGRERR_NONE)
>   {
>     ReportOgrError(err);
>   }
>   return S_OK;
> }
>
> STDMETHODIMP CGeoProjection::ImportFromWKT(const BSTR proj, 
> VARIANT_BOOL* retVal)
> {
>   AFX_MANAGE_STATE(AfxGetStaticModuleState())
>   USES_CONVERSION;
>
>   const CString s = OLE2A(proj);
>   const OGRErr err = ProjectionHelper::ImportFromWkt(_projection, s);
>
>   *retVal = err == OGRERR_NONE ? VARIANT_TRUE : VARIANT_FALSE;
>   if (err != OGRERR_NONE)
>   {
>     ReportOgrError(err);
>   }
>   return S_OK;
> }
>
> And from ProjectionHelper.cpp:
> OGRErr ProjectionHelper::ImportFromEsri(OGRSpatialReference* sr, 
> CString proj)
> {
>   if (!sr) {
>     return false;
>   }
>
>   char* s = proj.GetBuffer();
>   return sr->importFromESRI(&s);
> }
>
> OGRErr ProjectionHelper::ImportFromWkt(OGRSpatialReference* sr, 
> CString proj)
> {
>   if (!sr) {
>     return false;
>   }
>
>   char* s = proj.GetBuffer();
>   return sr->importFromWkt(&s);
> }
>
> We're currently upgrading from GDAL2+ to GDAL3+.
> Users report the crash in both versions.
>
> Most likely we're not calling the importFromESRI correctly.
> Please advice.
>
> Regards,
>
> Paul Meems
> https://github.com/MapWindow/MapWinGIS
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220204/a0516c78/attachment.html>


More information about the gdal-dev mailing list