qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.32k stars 2.97k forks source link

Crash after using a QgsLineString Object with dropped Z-values as a Geometry #41612

Open tschmetzer opened 3 years ago

tschmetzer commented 3 years ago

In pygis I am performing geometry operations on a QgsLineString Object with dropped Z-values which is why I need to convert it to a Geometry. Using that Geometry directly produces a crash when using a shapefile with example data. In the beginning I tried to reproduce the crash with manually introduced points which didn't work although similar calls are used.

The probably most essential steps before the crash:

    wall_lineString=convert_multi_polygon_to_QgsLineString(wall_multi_polygon)
    # drop all z values
    wall_lineString.dropZValue()
    new_wall_lineString=QgsLineString(wall_lineString)

The crash seems to occur with either command:

The crash doesn't occur when new_wall_lineString is used instead of wall_lineString. Also as it doesn't occur with my manual test data nor with the use of QgsGeometry(wall_lineString) itself it seems to be rather something particular than something general.

I will append

Underneath a Stack Trace:

QXmlStreamStringRef::~QXmlStreamStringRef : meth_QgsLineString_geometryType sip_corepart5.cpp:267988 PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyEval_EvalCodeEx : PyEval_EvalCode : PyArena_Free : PyRun_StringFlags : PyImport_Import : PyImport_Import : PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyImport_Import : PyImport_Import : PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyFunction_FastCallDict : PyMethodDef_RawFastCallDict : PyObject_Call : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : QMetaObject::activate : QAction::activate : QAbstractButton::click : QAbstractButton::mouseReleaseEvent : QToolButton::mouseReleaseEvent : QWidget::event : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify qgsapplication.cpp:458 QCoreApplication::notifyInternal2 : QApplicationPrivate::sendMouseEvent : QSizePolicy::QSizePolicy : QSizePolicy::QSizePolicy : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify qgsapplication.cpp:458 QCoreApplication::notifyInternal2 : QGuiApplicationPrivate::processMouseEvent : QWindowSystemInterface::sendWindowSystemEvents : QEventDispatcherWin32::processEvents : UserCallWinProcCheckWow : DispatchMessageWorker : QEventDispatcherWin32::processEvents : qt_plugin_query_metadata : QEventLoop::exec : QCoreApplication::exec : main main.cpp:1637 BaseThreadInitThunk : RtlUserThreadStart :

QGIS Info QGIS Version: 3.16.3-Hannover QGIS code revision: 94ac9f21b8 Compiled against Qt: 5.11.2 Running against Qt: 5.11.2 Compiled against GDAL: 3.1.4 Running against GDAL: 3.1.4

System Info CPU Type: x86_64 Kernel Type: winnt Kernel Version: 10.0.19041

geometry_problem.zip

elpaso commented 3 years ago

@tschmetzer I'm not saying that there isn't a bug here (I didn't dig into your code) but I think that it might be good to give some more general context about working with Python bindings, here is an old but still valid article about the inherent fragility of Python-C++ bindings: http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html

The bottom line is that there are multiple ways you can crash QGIS from Python and most of them can only be avoided with a deep knowledge of the underlying API or by sticking to well-known, tested and documented patterns and workarounds (like keeping local references in Python).

Most of the crashes a typical user can get are probably won't fix in the foreseeable future.

github-actions[bot] commented 3 years ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.