Bug report #13084

Segfault when accessing geometry from Python console

Added by Daniel Baston over 9 years ago. Updated over 9 years ago.

Status:Closed
Priority:High
Assignee:-
Category:PyQGIS Console
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:duplicate
Crashes QGIS or corrupts data:Yes Copied to github as #:21151

Description

Load the test data. Open python console. Run


iface.activeLayer().selectedFeatures()[0].geometry().exportToWkt()

Get

Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f4a0b337dcc in QgsAbstractGeometryV2::wkbType (this=0x21) at /home/dbaston/dev/QGIS/src/core/geometry/qgsabstractgeometryv2.h:117
117 QgsWKBTypes::Type wkbType() const { return mWkbType; }

Not sure that the test data actually matters.

Build 8e488ca. Originally experienced the problem w/QGIS 2.6, where .exportToWkt() would produce an empty string and .asWkb() would dump random memory contents.

test.zip (2.48 KB) Daniel Baston, 2015-07-06 09:25 AM


Related issues

Duplicates QGIS Application - Bug report #777: crashes with python reference to destroyed objects (e.g e... Closed

History

#1 Updated by Daniel Baston over 9 years ago

#2 Updated by Martin Dobias over 9 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

Duplicate of #777.

A solution is to keep temporary reference to the feature you work with:

f = iface.activeLayer().selectedFeatures()[0]
print f.geometry().exportToWkt()

This will avoid destruction of QgsFeature instance while its QgsGeometry object is still in use.

Also available in: Atom PDF