Bug report #15311

Issue with QgsVectorLayerUndoCommand class (QGIS crashes)

Added by gcarrillo - 11 months ago. Updated about 2 months ago.

Status:Open
Priority:High
Assignee:-
Category:Vectors
Affected QGIS version:2.18.4 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes

Description

I've discovered an issue with QgsVectorLayerUndoCommand class (QgsVectorLayerUndoCommandChangeAttribute.undo() method) when updating an attribute value after featureAdded SIGNAL is emitted.

Steps to reproduce:

1. Open QGIS, load a sample vector layer like this ( http://downloads.tuxfamily.org/tuxgis/tmp/test_point.zip ) and select it in the Layer List Widget (ToC).
2. Run the following code snippet into the QGIS Python Console to connect featureAdded SIGNAL to a custom SLOT that changes an attribute value:

myLayer = iface.activeLayer()
field = 0   # Please use the test Shapefile provided, if not, adjust the field index

def updateFeatureAttrs( fId ):
    f = myLayer.getFeatures( QgsFeatureRequest( fId ) ).next()
    geom = f.geometry()
    myLayer.changeAttributeValue( fId, field, geom.asPoint().x() )

myLayer.featureAdded.connect( updateFeatureAttrs )

3. Start editing. Add a new point. (If a form opens click on OK). Don't save anything.
4. Stop editing and choose "Close without saving."
5. QGIS crashes and prints the following error message:

%%%%%%%%%%%%%%%%%
Fatal: ASSERT: "it != mBuffer->mAddedFeatures.end()" in file
/tmp/buildd/qgis-2.14.2+20trusty/src/core/qgsvectorlayerundocommand.cpp,
line 255
Stacktrace (piped through c++filt):
/usr/bin/qgis.bin[0x40a440]
/usr/bin/qgis.bin[0x40a548]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(qt_message_output(QtMsgType, char
const*)+0x21)[0x7fd508939bb1]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(+0x70ff9)[0x7fd508939ff9]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(qFatal(char const*,
...)+0x94)[0x7fd50893a804]
/usr/lib/libqgis_core.so.2.14.2(QgsVectorLayerUndoCommandChangeAttribute::undo()+0x659)[0x7fd5092e2c09]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QUndoCommand::undo()+0x50)[0x7fd5084144e0]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QUndoStack::setIndex(int)+0xc8)[0x7fd508414e58]
/usr/lib/libqgis_core.so.2.14.2(QgsVectorLayerEditBuffer::rollBack()+0x23)[0x7fd5092c4d43]
/usr/lib/libqgis_core.so.2.14.2(QgsVectorLayer::rollBack(bool)+0x46)[0x7fd5092b81e6]
/usr/lib/libqgis_app.so.2.14.2(QgisApp::toggleEditing(QgsMapLayer*,
bool)+0xb4b)[0x7fd50a1b677b]
/usr/lib/libqgis_app.so.2.14.2(+0x478d41)[0x7fd50a4edd41]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QMetaObject::activate(QObject*,
QMetaObject const*, int, void**)+0x2da)[0x7fd508a5a87a]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QAction::triggered(bool)+0x32)[0x7fd507dd9a62]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QAction::activate(QAction::ActionEvent)+0x63)[0x7fd507ddb433]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x57cb02)[0x7fd508192b02]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QAbstractButton::mouseReleaseEvent(QMouseEvent*)+0x6c)[0x7fd508192c2c]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QToolButton::mouseReleaseEvent(QMouseEvent*)+0xa)[0x7fd508249a4a]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QWidget::event(QEvent*)+0xaca)[0x7fd507e2f50a]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QApplicationPrivate::notify_helper(QObject*,
QEvent*)+0x8c)[0x7fd507ddfe2c]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QApplication::notify(QObject*,
QEvent*)+0x3ad)[0x7fd507de65dd]
/usr/lib/libqgis_core.so.2.14.2(QgsApplication::notify(QObject*,
QEvent*)+0x5b)[0x7fd509049c8b]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QCoreApplication::notifyInternal(QObject*,
QEvent*)+0x6d)[0x7fd508a464dd]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QApplicationPrivate::sendMouseEvent(QWidget*,
QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&,
bool)+0x153)[0x7fd507de5d93]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x2449cb)[0x7fd507e5a9cb]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(QApplication::x11ProcessEvent(XEvent*)+0x1559)[0x7fd507e5a269]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x26bb02)[0x7fd507e81b02]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x254)[0x7fd500ceee04]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x49048)[0x7fd500cef048]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c)[0x7fd500cef0ec]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)+0x71)[0x7fd508a737a1]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x26bbb6)[0x7fd507e81bb6]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)+0x2f)[0x7fd508a450af]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)+0x175)[0x7fd508a453a5]
/usr/lib/x86_64-linux-gnu/libQtCore.so.4(QCoreApplication::exec()+0x89)[0x7fd508a4ab79]
/usr/bin/qgis.bin[0x406fd7]
/lib/x86_64-linux-gnu/libc.so.6(
_libc_start_main+0xf5)[0x7fd507358ec5]
/usr/bin/qgis.bin[0x409d48]
Aborted
%%%%%%%%%%%%%%%%%

I've tested both Shapefiles and SpatiaLite layers, getting the same error.

Do you have an idea of what could be happening?

I'm using QGIS v.2.14.2 on a Linux Mint machine and also confirmed the crash using QGIS v.2.14.1 on Windows 7.

History

#1 Updated by Martin Dobias 11 months ago

Unfortunately currently if you connect to one of the layer "editing" signals, issuing further editing commands will break the undo stack of the layer (because the previous undo command is not fully finished when a new undo command appears). A workaround for the meanwhile is to delay the follow up editing command - e.g. by making the connection "queued" or by using a QTimer with zero timeout or something similar...

#2 Updated by gcarrillo - 11 months ago

Thank you Martin for your comments. I've been trying with 3 layer editing SIGNALs (featureAdded, geometryChanged, and attributeValueChanged) and the only one that seems to fail is featureAdded. The other 2 don't make QGIS crash and allow QGIS to undo the edits properly.

#3 Updated by Giovanni Manghi 5 months ago

  • Priority changed from Normal to High

#4 Updated by Giovanni Manghi 4 months ago

  • Target version changed from Future Release - High Priority to Version 2.18
  • Affected QGIS version changed from 2.14.2 to 2.18.4

#5 Updated by Giovanni Manghi about 2 months ago

  • Easy fix? set to No
  • Regression? set to No

Also available in: Atom PDF