[geos-devel] segfault against 3.3.0 C++

Matt Perry perrygeo at gmail.com
Thu Sep 8 20:01:50 EDT 2011


Apologies in advance if this is due to my rusty C++ skills. I've got
some code (from the starspan project) which uses the C++ API to GEOS.
It worked fine against 3.2.2 but is now segfaulting against 3.3.0:

Program received signal SIGSEGV, Segmentation fault.
geos::geom::Polygon::getNumInteriorRing (this=0x66e0e8) at Polygon.cpp:194
194		return holes->size();
(gdb) backtrace
#0  geos::geom::Polygon::getNumInteriorRing (this=0x66e0e8) at Polygon.cpp:194
#1  0x0000000000427768 in Traverser::processPolygon
(this=0x7fffffffd7c0, poly=<value optimized out>) at
src/traverser/traverser.cc:425
...

In an attempt to debug, i tried to write the WKT to stderr... GEOS
segfaults at WKTWriter...
starspan2: WKTWriter.cpp:228: void
geos::io::WKTWriter::appendGeometryTaggedText(const
geos::geom::Geometry*, int, geos::io::Writer*): Assertion `0' failed.
( assert(0); // Unsupported Geometry implementation )

Program received signal SIGABRT, Aborted.
0x00007ffff64a7d05 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) backtrace
#0  0x00007ffff64a7d05 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff64abab6 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff64a07c5 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007ffff709dceb in
geos::io::WKTWriter::appendGeometryTaggedText (this=0x7fffffffd8f4,
geometry=0x66e0d0, level=0, writer=0x7fffffffd430) at
WKTWriter.cpp:228
...
#6  0x0000000000427697 in Traverser::processPolygon
(this=0x7fffffffd740, poly=<value optimized out>) at
src/traverser/traverser.cc:420


The relevant code from the starspan code that causes the geos segfaults is:

   405	void Traverser::processPolygon(OGRPolygon* poly) {
   406		Polygon* geos_poly = (Polygon*) poly->exportToGEOS();
   407		if ( geos_poly->isValid() ) {
...
   413		}
   414		else {
   415			summary.num_invalid_polys++;
   416			
   417			if ( globalOptions.skip_invalid_polys ) {
...
   420					cerr<< "geos_poly = " << wktWriter.write(geos_poly) << endl;
...
   422			}
   423			else {
   424				// try to explode this poly into smaller ones:
   425				if ( geos_poly->getNumInteriorRing() > 0 ) {
   426					cerr<< "--Invalid polygon has " <<geos_poly->getNumInteriorRing()
   427	                    << " interior rings: cannot explode it--" << endl;
   428					summary.num_polys_with_internal_ring++;
   429				}

So, as I understand it, geos_poly->getNumInteriorRing() and
wktWriter(geos_poly) are both segfaulting. Any ideas on the underlying
cause of the problem? I assumed a bad geometry but I have checked the
input geometery externally using python OGR on the same system (see
attached) and it is valid according to geos3.3 - maybe something to do
with the cast from OGRGeometery to GEOS Polygon or the exportToGeos()
?

How should I update this code for geos 3.3.0 and proceed with
debugging this issue?

-- 
·´¯`·.¸. , . .·´¯`·.. ><((((º>`·.¸¸.·´¯`·.¸.·´¯`·...¸><((((º>
"The best way to predict the future is to invent it."  -- Alan Kay
Matthew T. Perry
http://www.perrygeo.net
http://viedevelo.wordpress.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geom_1315445112.59.json
Type: application/json
Size: 79409 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/geos-devel/attachments/20110908/c703fa5a/geom_1315445112.59-0001.bin


More information about the geos-devel mailing list