opengisch / autocurve

QGIS plugin adding split/merge for curved geometries
1 stars 1 forks source link

Hard crash in QGIS 3.22 when editing attributes in the table with autocurve enabled #6

Closed olivierdalang closed 2 years ago

olivierdalang commented 2 years ago

Experiencing hard crash in QGIS 3.22 when editing attributes in the table with autocurve enabled

Steps to reproduce:

Full details:

Crash ID: [af3f0f57d3dd98b90853fc1e2a233cdce12e9770](https://github.com/qgis/QGIS/search?q=af3f0f57d3dd98b90853fc1e2a233cdce12e9770&type=Issues)

Stack Trace

QgsLineString::pointN :
QgsLineSegment2D::lengthSquared :
QgsLineSegmentDistanceComparer::operator() :
QgsLineSegmentDistanceComparer::operator() :
QgsGeometry::convertToCurves :
QgsRasterBooleanLogicAlgorithmBase::group :
PyInit__core :
PyArg_ParseTuple_SizeT :
PyEval_EvalFrameDefault :
PyObject_GC_Del :
PyFunction_Vectorcall :
PyEval_EvalFrameDefault :
PyObject_GC_Del :
PyFunction_Vectorcall :
PyEval_EvalFrameDefault :
PyFunction_Vectorcall :
PyFloat_FromDouble :
PyVectorcall_Call :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QObject::qt_static_metacall :
QgsVectorLayer::endEditCommand :
QgsAttributeTableDelegate::setModelData :
QAbstractItemView::commitData :
QObject::qt_static_metacall :
QAbstractItemDelegate::commitData :
QAbstractItemDelegate::destroyEditor :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::setFocusWidget :
QWidget::setFocus :
QApplicationPrivate::giveFocusAccordingToFocusPolicy :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.22.4-Bia?owie?a
QGIS code revision: ce8e65e9
Compiled against Qt: 5.15.2
Running against Qt: 5.15.2
Compiled against GDAL: 3.4.1
Running against GDAL: 3.4.1

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.19043
olivierdalang commented 2 years ago

Was able to reproduce, it is an upstream issue. The same crash can be reproduced with the following procedure:

Here it happens on QGIS 3.16.16 too though (with a hang instead of a crash).

Still I think I can come up with a workaround, as changing the attributes does not need to run the tool.

olivierdalang commented 2 years ago

Hmm, actually I can't reproduce it reliably. It seems the crash depends on the geometry, and by the way also on 3.16. Will push the workaround mentioned above, then if it's not solved we may need to open another issue with some sample data (which will probably be an issue upstream).

For further reference, here's a crash (both in QGIS 3.22 and 3.16):

from processing.gui import AlgorithmExecutor
import math

def make_layer_with_feature(wkt):
    # Prepare a feature
    f = QgsFeature()
    f.setGeometry(QgsGeometry.fromWkt(wkt))
    f.setAttributes(["Ada"])
    # Create a layer with that feature
    vl = QgsVectorLayer("CurvePolygon", "temp", "memory")
    vl.dataProvider().addAttributes([QgsField("name", QVariant.String)])
    vl.dataProvider().addFeature(f)
    # Add to the project and select it
    QgsProject.instance().addMapLayer(vl)
    iface.setActiveLayer(vl)

params = {"DISTANCE": 1e-6, "ANGLE": 1e-6}
alg = QgsApplication.processingRegistry().createAlgorithmById('native:converttocurves')

# Works
points = [f"{math.cos(math.radians(a))} {math.sin(math.radians(a))}" for a in range(0,180)]
segmented_arc_wkt = f"POLYGON((({','.join(points + [points[0]])})))"
make_layer_with_feature(segmented_arc_wkt)
AlgorithmExecutor.execute_in_place(alg, params)

# Crashes
curved_arc_wkt = "CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING (0 0,1 1,2 0),(2 0,0 0)))"
make_layer_with_feature(curved_arc_wkt)
AlgorithmExecutor.execute_in_place(alg, params)