Bug report #5747

Crash after calling QgsMapLayerRegistry::addMapLayers

Added by Giuseppe Sucameli almost 12 years ago. Updated almost 12 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python plugins
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:15253

Description

The QgsMapLayerRegistry.addMapLayer is deprecated but the newer version QgsMapLayerRegistry.addMapLayers if called two times cause segfault.

From the python console:

vl1 = QgsVectorLayer("/home/brushtyler/vl1", "test", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([vl1])

vl2 = QgsVectorLayer("/home/brushtyler/vl2", "test", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([vl2])

Confirmed on both Win7 and Ubuntu 11.04, QGis 1.8

Associated revisions

History

#1 Updated by Giovanni Manghi almost 12 years ago

is this a regression since 1.7.4?

#2 Updated by Giuseppe Sucameli almost 12 years ago

Giovanni Manghi wrote:

is this a regression since 1.7.4?

no, the QgsMapLayerRegistry::addMapLayers() method is new in 1.8 (it wasn't present in 1.7.x)

#3 Updated by Larry Shaffer almost 12 years ago

Giuseppe,

I attempted to confirm with 1.8_1125571 on Mac OS X 10.6.8 and Ubuntu 12.04, but I couldn't get QgsMapLayerRegistry.addMapLayers() to work without an exception being raised:

TypeError: QgsMapLayerRegistry.addMapLayers(list-of-QgsMapLayer, bool theEmitSignal=True): first argument of unbound method must have type 'QgsMapLayerRegistry'

I tried from qgis.core import QgsMapLayerRegistry but ends in same exception.

However, I had no issues adding 7 layers with QgsMapLayerRegistry.instance().addMapLayers(), as long as I did not use an existing layer name as the second parameter to the QgsVectorLayer constructor.

This works on both platforms:

v1 = QgsVectorLayer("/data/hr_100kdlg/hr-bnd.shp", "test1", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([v1])
v2 = QgsVectorLayer("/data/hr_100kdlg/hr-rds.shp", "test2", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([v2])
...
v7 = QgsVectorLayer("/data/hr_100kdlg/hr-quads.shp", "test7", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([v7])

but this causes the crash on both platforms (sometimes took 3 layers):

v1 = QgsVectorLayer("/data/hr_100kdlg/hr-bnd.shp", "samename", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([v1])
v2 = QgsVectorLayer("/data/hr_100kdlg/hr-rds.shp", "samename", "ogr")
QgsMapLayerRegistry.instance().addMapLayers([v2])

Does it still crash on your tested platforms when using dissimilar layer names in QgsVectorLayer constructor?

#4 Updated by Jürgen Fischer almost 12 years ago

  • Category changed from Map Canvas to Python plugins

#5 Updated by Jürgen Fischer almost 12 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF