Bug report #7674

crash after adding map layer to registry

Added by Josef Källgården about 11 years ago. Updated about 11 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:Map Canvas
Affected QGIS version:master Regression?:No
Operating System:win7, ubuntu 12.04, debian Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:16591

Associated revisions

Revision b98db884
Added by Matthias Kuhn about 11 years ago

[Fix #7674] Transfer ownership of layer to C++ when added to the registry

History

#1 Updated by Josef Källgården about 11 years ago

from the python console:

uri = QgsDataSourceURI()
uri.setDatabase('/home/josef/Documents/sqlite_db.sqlite')
uri.setDataSource('','table1', 'Geometry')
layer = QgsVectorLayer(uri.uri(), 'table1', 'spatialite')
QgsMapLayerRegistry.instance().addMapLayers([layer])

If the code above is pasted into python console with an additional end-of-line so that all lines are executed immediately, then this causes segmentation fault on both win 7 and ubuntu 12.04. Sometimes directly and sometimes after changing visibility for the layer.

If last line is executed after a short pause, then no crash.

#2 Updated by Borys Jurgiel about 11 years ago

  • Operating System changed from win7, ubuntu 12.04 to win7, ubuntu 12.04, debian

I just observed very similar problem: After a plugin adds a map layer to the QgsMapLayerRegistry, a first action done on that layer (remove, visibility change, attribute table open) causes a crash.

#3 Updated by Matthias Kuhn about 11 years ago

  • Status changed from Open to Feedback

Not reproducible here with a shapefile. Is this specific to sqlite?

#4 Updated by Josef Källgården about 11 years ago

Yes, this is specific to a spatial spatialite table.
A shape file is ok. So is also a non-spatial spatialite added by ogr.

Matthias Kuhn wrote:

Not reproducible here with a shapefile. Is this specific to sqlite?

#5 Updated by Matthias Kuhn about 11 years ago

  • Status changed from Feedback to Open
  • Subject changed from crash after QgsMapLayerRegistry.instance().addMapLayers([sp to [spatialite] crash after adding map layer to registry

#6 Updated by Matthias Kuhn about 11 years ago

  • Category set to Data Provider/SpatiaLite

#7 Updated by Josef Källgården about 11 years ago

Same problems with memory layers:

ml = QgsVectorLayer("Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes", "temporary_points", "memory")
QgsMapLayerRegistry.instance().addMapLayers([ml])

This causes a crash after turning visibility on/off, opening attribute table etc. Sometimes the crash occurs after a second addition of a memory layer.

#8 Updated by Borys Jurgiel about 11 years ago

I can confirm the problem also with Shapefiles when using plugins like TableManager or Shapefile Encoding Fixer. They both use QgsMapLayerRegistry.instance().addMapLayers([layer]) after applying changes.

So if you can confirm this, please extend the title and category from SpatiaLite back to general QgsVectorLayer.

#9 Updated by Borys Jurgiel about 11 years ago

See also #7677

#10 Updated by Josef Källgården about 11 years ago

I made a few more tests and yes, I can confirm crashes for shape files when using the plugins. Also, new memory layer plugin results in crash (same usage of addMapLayers).

Can someone with the necessary permissions change title and category according to Borys suggestion?

#11 Updated by Borys Jurgiel about 11 years ago

  • Subject changed from [spatialite] crash after adding map layer to registry to crash after adding map layer to registry
  • Category changed from Data Provider/SpatiaLite to Map Canvas

I'm not really sure which category fits the QgsMapLayerRegistry to.

#12 Updated by Matthias Kuhn about 11 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF