Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#1248 closed bug (duplicate)

QgsGeometry.Union causes Segfault when unioning multi-polyon features

Reported by: cfarmer Owned by: jef
Priority: critical: causes crash or data corruption Milestone:
Component: Vectors Version: Trunk
Keywords: Cc:
Must Fix for Release: Yes Platform: Linux
Platform Version: Awaiting user input: no

Description

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):

geom = QgsGeometry() geom2 = QgsGeometry() provider.getNextFeature(feat) geom = feat.geometry() while provider.getNextFeature(feat):

geom2 = feat.geometry() geom = geom.Union(geom2)

Change History (2)

comment:1 by jef, 16 years ago

Resolution: duplicate
Status: newclosed

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])

comment:2 by (none), 15 years ago

Milestone: Version 1.0.0

Milestone Version 1.0.0 deleted

Note: See TracTickets for help on using tickets.