Closed jamiecook closed 7 years ago
Thanks for making the test! I think I know the issue. Will try to push something later today.
Ack! don't leave me hangin'!!!!
I've been doing some debugging of my own but don't have a solid idea yet - can you give a newbie a 2min version of your idea?
Sure. The issue (I think!) has to do with the transfer of ownership of individual Geometry objects that belong to a MultiGeometry object. If you look in Raw.CoordSeq, you'll notice a CoordinateSequence class, that has instances for both CoordSeq and CoordSeqConst. The idea is that: sometimes you might want a coordinate sequence that lives completely separate from whatever geometry once owned it -- and sometimes you might want to just peek at the value, but let the parent geometry continue to own it.
The same thing needs to be done for Geometry.
What's happening in some cases is that the functions that convert between Haskell types and C types are unclear about whether the sub-geometries they want are ones that maintain parent ownership and ones that do not maintain parent ownership. So in a couple places we're adding a finalizer to an object whose parent (which retains ownership) already has a finalizer attached. The first one deallocates the child object through the parent, and the one attached to the child results in a "pointer being freed was not allocated" error.
The solution that I've started on is creating a Geometry class, which has instances for Geom (a type with a finalizer) and GeomConst (a type without a finalizer). Most functions will use the instance method for accessing these, but certain functions that expect the object to maintain parent ownership can specify that in their type.
Does that make sense?
Ah yes it does! And it's not something I would have been able to get to the bottom of easily.
Just to be clear, in general I should be able to (for Polygons say) use the returned objects without being in the Geos monad right? For example:
I also emailed you separately to this - do you happen to have any good examples of using the library (esp to talk to PostGIS). I'm thinking that I might be able to help out with drafting some examples into the README, but I'm still a bit unsure whether I'm using the library right.
The reason I ask is that even when I use PostGIS to break the multipolygon up into simple polygons
SELECT encode((ST_DUMP(ST_Simplify(wkb_geometry::geometry, 0.01))).geom::geometry(Polygon,4326), 'hex')
FROM my_table
I get a core dump on that show line ?
Have you seen this issue after recent fixes?
No i'm pretty sure this was closed off in an earlier PR.
Hi,
I'm having real problems with MultiPolygons which I think I have reproduced in the tests (branch PR is here: https://github.com/ewestern/geos/pull/3)
Basically the following hex encodes a multi polygon
which looks like this when it's parsed
But testing this seems to cause seg faults.
Happy to help with debugging this but don't really know where to start.