Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Console crashes when removing non-existent vector layer #17

Open
rduivenvoorde opened this issue Jun 25, 2016 · 9 comments
Open

Comments

@rduivenvoorde
Copy link
Owner

rduivenvoorde commented Jun 25, 2016

Imported from Redmine: http://hub.qgis.org/issues/10755
Originally created on Mon Jun 30 02:16:22 -0700 2014, last update on Sat Nov 07 06:02:05 -0800 2015
Author: @rduivenvoorde rduivenvoorde@foo.bar (Q: should we show email?, Q: should we create @ mention?)

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\rauni\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.

@rduivenvoorde
Copy link
Owner Author

crash.py (Q: only zips are supported!)

crash.py.zip

@rduivenvoorde
Copy link
Owner Author

no_crash.py

no_crash.py.zip

@rduivenvoorde
Copy link
Owner Author

rduivenvoorde commented Jun 25, 2016

minidump added by Rauni Lillemets

qgis-20140630-120940-6060-5464-8fdd08a.zip

@rduivenvoorde
Copy link
Owner Author

@m-kuhn:

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())

@rduivenvoorde
Copy link
Owner Author

@gioman

set/changed Category, Prio, Causes crash or corruption

@rduivenvoorde
Copy link
Owner Author

@jef-n

@m-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 #16 (#777.)

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

@rduivenvoorde
Copy link
Owner Author

@gioman

Should we close this as duplicate?

@rduivenvoorde
Copy link
Owner Author

Updated by Jürgen Fischer/jef-n

Status changed from Feedback to Closed
Resolution set to duplicate

@rduivenvoorde
Copy link
Owner Author

Just added a label Temporary, looking what happens with that if we would clean up the labels later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant