Bug report #10755

Python Console crashes when removing non-existent vector layer

Added by Rauni Lillemets over 3 years ago. Updated about 2 years ago.

Status:Closed
Priority:High
Assignee:-
Category:PyQGIS Console
Affected QGIS version:2.4.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:duplicate
Crashes QGIS or corrupts data:Yes

Description

When I try to run the following code (included in attachment crash.py) from Python Console, the QGis crashes by saying:

minidump written to C:\\Users\
auni\\AppData\\Local\\Temp\\qgis-20140630-120940-6060-5464-8fdd08a.dmp (see attached minidump)

However, if I run the code (included in attachment no_crash.py), then no error occurs.

Code is following:

iface = qgis.utils.iface

rasterLayer = iface.addRasterLayer("crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/png&layers=natura2000&styles=&url=http://geodata.nationaalgeoregister.nl/natura2000/ows", "wms master example", "wms" ) 
vectorLayer = iface.addVectorLayer("http://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=bestuurlijkegrenzen:provincies&SRSNAME=EPSG:28992","wfs example","WFS")

#QgsMapLayerRegistry.instance().addMapLayer(vectorLayer) #if this line is commented out, a crash occurs.

# additional code...

QgsMapLayerRegistry.instance().removeMapLayer(vectorLayer.id())

I am using the versions:
QGIS versioon 2.4.0-Chugiak
QGIS koodi revisjon 8fdd08a
Kompileeritud Qt-le 4.8.5
Töötab Qt-s 4.8.5
Kompileeritud GDAL/OGR-le 1.11.0
Töötab GDAL/OGR-s 1.11.0
Compiled against GEOS 3.4.2-CAPI-1.8.2
Running against GEOS 3.4.2-CAPI-1.8.2 r3921
PostgreSQL kliendi versioon 9.2.4
SpatiaLite versioon 4.1.1
QWT versioon 5.2.3
PROJ.4 Versioon 480
QScintilla2 Version 2.7.2

I am using Windows 7, if it matters.

crash.py Magnifier - crash file (1.24 KB) Rauni Lillemets, 06/30/2014 02:16 AM

no_crash.py Magnifier - no crash occurs. (1.24 KB) Rauni Lillemets, 06/30/2014 02:16 AM

qgis-20140630-120940-6060-5464-8fdd08a.zip - minidump (3.55 MB) Rauni Lillemets, 06/30/2014 02:17 AM


Related issues

Related to QGIS Application - Bug report #777: crashes with python reference to destroyed objects (e.g e... Closed

History

#2 Updated by Matthias Kuhn over 3 years ago

Crashes here only in the following order:

rasterLayer = iface.addRasterLayer("crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/png&layers=natura2000&styles=&url=http://geodata.nationaalgeoregister.nl/natura2000/ows", "wms master example", "wms" ) 
vectorLayer = iface.addVectorLayer("http://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=bestuurlijkegrenzen:provincies&SRSNAME=EPSG:28992","wfs example","WFS")

QgsMapLayerRegistry.instance().removeMapLayer(vectorLayer.id())
QgsMapLayerRegistry.instance().addMapLayer(vectorLayer) #if this line is commented out, a crash occurs.
QgsMapLayerRegistry.instance().removeMapLayer(vectorLayer.id())

#3 Updated by Giovanni Manghi over 3 years ago

  • Crashes QGIS or corrupts data changed from No to Yes
  • Priority changed from Normal to High
  • Category set to PyQGIS Console

#4 Updated by Jürgen Fischer about 2 years ago

  • Status changed from Open to Feedback

Matthias Kuhn wrote:

Crashes here only in the following order:

[...]

More detailed:
  • QgsMapLayerRegistry.addMapLayer transfers ownership of the layer
  • QgsMapLayerRegistry.removeMapLayer in turn destructs the layer
  • The python object vectorLayer doesn't notice and hence the call to vectorLayer.id() crashes (before removeMapLayer is even called a second time)

So that's a flaw in the API and a duplicate of #777.

But crash.py doesn't use the layer after it has been removed and doesn't crash here on master.

#5 Updated by Jürgen Fischer about 2 years ago

  • Subject changed from Python Console crashes when removing non-existant vector layer to Python Console crashes when removing non-existent vector layer

#6 Updated by Giovanni Manghi about 2 years ago

Should we close this as duplicate?

#7 Updated by Jürgen Fischer about 2 years ago

  • Resolution set to duplicate
  • Status changed from Feedback to Closed

Also available in: Atom PDF