paulsmith / gogeos

Go library for spatial data operations and geometric algorithms (Go bindings for GEOS)
http://paulsmith.github.io/gogeos/
MIT License
280 stars 79 forks source link

Geometry.String() results in segmentation violation for MULTIPOLYGON #24

Open oceanful opened 5 years ago

oceanful commented 5 years ago

Geometry.String() works for POINT and LINEARRING, but results in a segmentation violation when called on a MULTIPOLYGON.

Code to reproduce:

triangle := geos.Must(geos.NewLinearRing(
    geos.NewCoord(0, 0),
    geos.NewCoord(1, 2),
    geos.NewCoord(2, 3),
    geos.NewCoord(0, 0),
))
multi := geos.Must(geos.NewCollection(geos.MULTIPOLYGON, triangle))
fmt.Printf("Triangle: %s\n", triangle.String())
fmt.Printf("Multi: %s\n", multi.String())

Result:

Triangle: LINEARRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000, 2.0000000000000000 3.0000000000000000, 0.0000000000000000 0.0000000000000000)
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x424ae24]

runtime stack:
runtime.throw(0x40d876b, 0x2a)
        /usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:374 +0x4a9

goroutine 1 [syscall]:
runtime.cgocall(0x409c2a0, 0xc000059dd0, 0x436ad98)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000059da0 sp=0xc000059d68 pc=0x40044cb
github.com/paulsmith/gogeos/geos._Cfunc_GEOSWKTWriter_write_r(0x5800000, 0x5000250, 0x5000168, 0x0)
        _cgo_gotypes.go:2371 +0x4e fp=0xc000059dd0 sp=0xc000059da0 pc=0x40973ae
github.com/paulsmith/gogeos/geos.cGEOSWKTWriter_write.func1(0x5000250, 0x5000168, 0x419e5c8)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/cwrappers.go:889 +0xcb fp=0xc000059e10 sp=0xc000059dd0 pc=0x4098edb
github.com/paulsmith/gogeos/geos.cGEOSWKTWriter_write(0x5000250, 0x5000168, 0x0)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/cwrappers.go:889 +0x7a fp=0xc000059e38 sp=0xc000059e10 pc=0x4097e6a
github.com/paulsmith/gogeos/geos.(*wktEncoder).encode(0xc0000aa040, 0xc0000aa028, 0x0, 0xb2, 0xc0000c0000, 0x0)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/wkt.go:62 +0x3f fp=0xc000059e60 sp=0xc000059e38 pc=0x409870f
github.com/paulsmith/gogeos/geos.(*Geometry).ToWKT(0xc0000aa028, 0xc0000b0000, 0x40d3934, 0xd, 0xc000059f78)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/geom.go:79 +0x31 fp=0xc000059ea0 sp=0xc000059e60 pc=0x4097fc1
github.com/paulsmith/gogeos/geos.(*Geometry).String(...)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/geom.go:85
main.main()
furstenheim-geoblink commented 4 years ago

Take a look at https://github.com/paulsmith/gogeos/issues/19 you need to add a runtime.Keepalive where you are using the object.