[geos-devel] Encounter Segmentation Fault with GEOS 2.2.2

Sheng Liang (SH/CBC) sheng.liang at ericsson.com
Thu Jun 29 02:23:45 EDT 2006


  Thank you.

  I compared your code with mine. It is my fault. I didn't
Pass a valid notice_function and an error_function when I call 
initGEOS().
  Now there is no segmenation fault. But an error still happen.
The error message is :
TopologyException: no outgoing dirEdge found (125.331,0)

  I can't dig into the source code of GEOS, for I don't know much about
it.
Did you encounter this error?

  Regards

-----Original Message-----
From: geos-devel-bounces at geos.refractions.net
[mailto:geos-devel-bounces at geos.refractions.net] On Behalf Of
strk at refractions.net
Sent: Wednesday, June 28, 2006 21:13
To: GEOS Development List
Subject: Re: [geos-devel] Encounter Segmentation Fault with GEOS 2.2.2

Ops, sorry, I fell in the initGEOS missing call myself.
Actually I can *not* reproduce the error against the 2.2 branch.

Here is my testcase, if you confirm it fails please send a backtrace, or
valgrind output.

----------------------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <geos_c.h>


int main()
{
        initGEOS(printf, printf);

   GEOSGeom aPolygon1,aPolygon2;

   const char *aString1 = "POLYGON ((125.331 0,3.35823e-06
125.331,-125.331 6.71
646e-06,-1.00747e-05 -125.331,125.331 0))";

   const char *aString2 = "POLYGON ((245.331 120,120 245.331,-5.331
120,120 -5.3
31,245.331 120))";


   aPolygon1 = GEOSGeomFromWKT(aString1);
   aPolygon2 = GEOSGeomFromWKT(aString2);

   GEOSGeom anIntersection = GEOSIntersection(aPolygon1,aPolygon2);

}

----------------------------------------------------------------------

--strk;


On Wed, Jun 28, 2006 at 01:51:59PM +0200, strk at refractions.net wrote:
> Oh, ok, I now remember to have fixed this in HEAD.
> Can you confirm ?
> 
> --strk;
> 
> On Wed, Jun 28, 2006 at 09:15:25AM +0800, Sheng Liang (SH/CBC) wrote:
> > Hi:
> >   Yes. I have called initGEOS() before I create those GEOSGeom.
> > As I said, if I provide some other polygons, there is no fault.
> > The fault just happened to these two specific polygons.
> > 
> >   Regards
> > 
> > -----Original Message-----
> > From: geos-devel-bounces at geos.refractions.net
> > [mailto:geos-devel-bounces at geos.refractions.net] On Behalf Of 
> > strk at refractions.net
> > Sent: Tuesday, June 27, 2006 23:45
> > To: GEOS Development List
> > Subject: Re: [geos-devel] Encounter Segmentation Fault with GEOS 
> > 2.2.2
> > 
> > Did you call initGEOS() ?
> > That's currently *required* (might change in the future)
> > 
> > --strk;
> > 
> > On Mon, Jun 26, 2006 at 12:07:48PM +0800, Sheng Liang (SH/CBC)
wrote:
> > > HI:
> > >   I have tried aString1.c_str(), but I still get the same error. 
> > > And I
> > 
> > > even use such code:
> > >    GEOSGeom aPolygon1,aPolygon2;
> > >    const char *aString1 = "POLYGON ((125.331 0,3.35823e-06
> > > 125.331,-125.331 6.71646e-06,-1.00747e-05 -125.331,125.331 0))";
> > > 
> > >    const char *aString2 = "POLYGON ((245.331 120,120 
> > > 245.331,-5.331 120,120 -5.331,245.331 120))";
> > > 
> > >         
> > >    aPolygon1 = GEOSGeomFromWKT(aString1);
> > >    aPolygon2 = GEOSGeomFromWKT(aString2);
> > >         
> > >    GEOSGeom anIntersection = 
> > > GEOSIntersection(aPolygon1,aPolygon2);
> > > 
> > > And the error is the same.
> > >   Regards
> > > 
> > > -----Original Message-----
> > > From: geos-devel-bounces at geos.refractions.net
> > > [mailto:geos-devel-bounces at geos.refractions.net] On Behalf Of 
> > > Mateusz Loskot
> > > Sent: Monday, June 26, 2006 11:49
> > > To: GEOS Development List
> > > Subject: Re: [geos-devel] Encounter Segmentation Fault with GEOS 
> > > 2.2.2
> > > 
> > > Sheng Liang (SH/CBC) wrote:
> > > > Hi: I encountered an error of "Segmentation Fault" with GEOS
2.2.2.
> > > > What I am doing is to get intersection of two polygons. The 
> > > > error happens to the specific polygong: POLYGON ((125.331 
> > > > 0,3.35823e-06
> > > > 125.331,-125.331 6.71646e-06,-1.00747e-05 -125.331,125.331 0)) 
> > > > and POLYGON ((245.331 120,120 245.331,-5.331 120,120 
> > > > -5.331,245.331
> > > > 120))
> > > 
> > > > There is no error to others polygons. So I think it must be an 
> > > > error
> > 
> > > > of GEOS 2.2.2 code.
> > > > 
> > > > My code is : GEOSGeom aPolygon1,aPolygon2; string 
> > > > aString1("POLYGON
> > > > ((125.331 0,3.35823e-06 125.331,-125.331 
> > > > 6.71646e-06,-1.00747e-05
> > > > -125.331,125.331 0))");
> > > > 
> > > > string aString2("POLYGON ((245.331 120,120 245.331,-5.331 
> > > > 120,120
> > > > -5.331,245.331 120))");
> > > > 
> > > > aPolygon1 = GEOSGeomFromWKT(aString1.data());
> > > > aPolygon2 = GEOSGeomFromWKT(aString2.data());
> > > 
> > > I'm suer in 99% that the problem is in your code above.
> > > You should not access internal buffer of std::string with data() 
> > > member function. It should be used in very rare cases because it 
> > > breaks OOP rule of encapsulation! It's available only for C
> > compatibility.
> > > 
> > > GEOSGeomFromWKT expects to get const char* :
> > > Geometry *GEOSGeomFromWKT(const char *wkt);
> > > 
> > > so, you should call it as follows:
> > > 
> > > aPolygon1 = GEOSGeomFromWKT(aString1.c_str());
> > > 
> > > std::string::c_str() returns const char*.
> > > 
> > > Cheers
> > > --
> > > Mateusz Loskot
> > > http://mateusz.loskot.net
> > > _______________________________________________
> > > geos-devel mailing list
> > > geos-devel at geos.refractions.net
> > > http://geos.refractions.net/mailman/listinfo/geos-devel
> > > _______________________________________________
> > > geos-devel mailing list
> > > geos-devel at geos.refractions.net
> > > http://geos.refractions.net/mailman/listinfo/geos-devel
> > 
> > --
> > 
> >  /"\    ASCII Ribbon Campaign
> >  \ /    Respect for low technology.
> >   X     Keep e-mail messages readable by any computer system.
> >  / \    Keep it ASCII. 
> > 
> > _______________________________________________
> > geos-devel mailing list
> > geos-devel at geos.refractions.net
> > http://geos.refractions.net/mailman/listinfo/geos-devel
> > _______________________________________________
> > geos-devel mailing list
> > geos-devel at geos.refractions.net
> > http://geos.refractions.net/mailman/listinfo/geos-devel
> 
> --
> 
>  /"\    ASCII Ribbon Campaign
>  \ /    Respect for low technology.
>   X     Keep e-mail messages readable by any computer system.
>  / \    Keep it ASCII. 
> 
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel

-- 

 /"\    ASCII Ribbon Campaign
 \ /    Respect for low technology.
  X     Keep e-mail messages readable by any computer system.
 / \    Keep it ASCII. 

_______________________________________________
geos-devel mailing list
geos-devel at geos.refractions.net
http://geos.refractions.net/mailman/listinfo/geos-devel



More information about the geos-devel mailing list