Bug report #1248
QgsGeometry.Union causes Segfault when unioning multi-polyon features
|Affected QGIS version:||Regression?:||No|
|Operating System:||Linux||Easy fix?:||No|
|Pull Request or Patch supplied:||Resolution:||duplicate|
|Crashes QGIS or corrupts data:|
When unioning two features using QgsGeometry.Union, if one of the features is a multi-polygon, QGIS crashes without warning.
Example (should combine all geometries of a single layer together through unioning):
#1 Updated by Jürgen Fischer about 10 years ago
- Resolution set to duplicate
- Status changed from Open to Closed
Looks like this is the same problem as #777. Union is simply called with a geometry that has already been destructed.
getNextFeature deletes the geometry of the first feature and therefore the geometry you retrieved earlier becomes invalid.
If you copy the geometry the crash disappears:
geom = [[QgsGeometry]]() p = iface.getMapCanvas().currentLayer().dataProvider() f = [[QgsFeature]]() p.getNextFeature(f) geom = [[QgsGeometry]](f.geometry()) while p.getNextFeature(f): geom = geom.Union( f.geometry() ) f = [[QgsFeature]]() f.setGeometry( geom ) p.addFeatures([f])