Bug report #21603

Crash when using QgsGeometry.delaunayTriangulation()

Added by Antoine Lafranchis over 5 years ago. Updated over 5 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.7(master) Regression?:No
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:29419

Description

Qgis crashes (with windows message "qgis-dev-bin-g7.exe has stopped working") after using QgsGeometry.delaunayTriangulation() in python script.

It reproduces when executing the attached processing script with the attached point layer.

Running the following code in python console can also trigger the crash, but it's sometimes necessary to run it twice:

pointLayer = iface.activeLayer()
multiPoint = QgsMultiPoint()
for pointFeature in pointLayer.getFeatures():
    multiPoint.addGeometry(pointFeature.geometry().vertexAt(0))

multiPointGeometry = QgsGeometry(multiPoint)
triangulation = multiPointGeometry.delaunayTriangulation(1e-3)
multiTriangle = triangulation.get()
for i in range(multiTriangle.numGeometries()):
    triangle = multiTriangle.geometryN(i)
    triangleGeometry = QgsGeometry(triangle)

test_points.dbf (110 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

test_points.cpg (5 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

test_points.prj (431 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

test_points.qpj (682 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

test_points.shp (212 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

test_points.shx (132 Bytes) Antoine Lafranchis, 2019-03-17 07:01 PM

TestTriangulation.py Magnifier (1.88 KB) Antoine Lafranchis, 2019-03-17 07:08 PM

History

#1 Updated by Nyall Dawson over 5 years ago

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

triangleGeometry = QgsGeometry(triangle)

Should be

triangleGeometry = QgsGeometry(triangle.clone())

You are "stealing" ownership of an already owned object, which leads to a crash

#2 Updated by Antoine Lafranchis over 5 years ago

Thanks, it works fine now!

Isn't it possible to throw exceptions instead of crashing in cases of ownership theft?

#3 Updated by Nyall Dawson over 5 years ago

I think it should be, but generating these bindings is very complex and sometimes fragile, so I'm not 100% confident. I'll give it a shot sometime.

Also available in: Atom PDF