Opened 10 years ago

Closed 9 years ago

#5300 closed defect (wontfix)

python binding : GetFeature() / GetNextFeature().GetGeometryRef() crashes

Reported by: elpaso Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 1.9.2
Severity: normal Keywords:
Cc:

Description

This is the code:

from osgeo import ogr

driver = ogr.GetDriverByName('ESRI Shapefile')
shape_handle=driver.Open('811.shp')

shape_srs = ogr.osr.SpatialReference()
shape_srs.ImportFromEPSG(23032)

dest_srs = ogr.osr.SpatialReference()
dest_srs.ImportFromEPSG(32632)

layer = shape_handle.GetLayerByIndex(0)
g = layer.GetFeature(0).geometry()
g.AssignSpatialReference(shape_srs)
g.TransformTo(dest_srs)

I'm on Ubuntu 12.04 64 bit LTS, python-gdal:

Installed: 1.9.2-2~precise4

gdal.VersionInfo() '1920'

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5c3165f in OGRGeometry::transformTo(OGRSpatialReference*) () from /usr/lib/libgdal.so.1
(gdb) bt
#0  0x00007ffff5c3165f in OGRGeometry::transformTo(OGRSpatialReference*) () from /usr/lib/libgdal.so.1
#1  0x00007fffe7e099a7 in ?? () from /usr/lib/python2.7/dist-packages/osgeo/_ogr.so
#2  0x000000000048abb8 in PyEval_EvalFrameEx ()
#3  0x000000000048d930 in PyEval_EvalCodeEx ()
#4  0x0000000000486bb8 in PyEval_EvalFrameEx ()
#5  0x000000000048d930 in PyEval_EvalCodeEx ()
#6  0x00000000004246a1 in PyRun_FileExFlags ()
#7  0x000000000042492e in PyRun_SimpleFileExFlags ()
#8  0x0000000000425cb6 in Py_Main ()
#9  0x00007ffff68cb76d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#10 0x000000000041bb31 in _start ()

Attachments (1)

shape_test.zip (4.7 KB ) - added by elpaso 10 years ago.
Test shapefile

Download all attachments as: .zip

Change History (3)

by elpaso, 10 years ago

Attachment: shape_test.zip added

Test shapefile

comment:1 by Even Rouault, 10 years ago

Component: defaultPythonBindings
Owner: changed from warmerdam to hobu
Summary: python binding core dump on TransformTopython binding : GetFeature() / GetNextFeature().GetGeometryRef() crashes

Yes, this is a known limitation of how ref-counting in the Python bindings works. This is mentionned in the "Python gotchas" wiki page at http://trac.osgeo.org/gdal/wiki/PythonGotchas . particularly in the section "Python crashes if you use an object after deleting an object it has a relationship with"

So you have to change a bit your code like this : feat = layer.GetFeature(0) g = feat.geometry()

So that the feature object stays alive while you need its geometry.

comment:2 by Even Rouault, 9 years ago

Resolution: wontfix
Status: newclosed

Closing as wontfix for now. There are other tickets related to that

Note: See TracTickets for help on using tickets.