Bug report #10755
Python Console crashes when removing non-existent vector layer
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 | Copied to github as #: | 19138 |
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.
Related issues
History
#1 Updated by Rauni Lillemets over 10 years ago
- File qgis-20140630-120940-6060-5464-8fdd08a.zip added
Added minidump
#2 Updated by Matthias Kuhn over 10 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 10 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 9 years ago
- Status changed from Open to Feedback
Matthias Kuhn wrote:
More detailed:Crashes here only in the following order:
[...]
QgsMapLayerRegistry.addMapLayer
transfers ownership of the layerQgsMapLayerRegistry.removeMapLayer
in turn destructs the layer- The python object
vectorLayer
doesn't notice and hence the call tovectorLayer.id()
crashes (beforeremoveMapLayer
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 9 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 9 years ago
Should we close this as duplicate?
#7 Updated by Jürgen Fischer about 9 years ago
- Resolution set to duplicate
- Status changed from Feedback to Closed