Bug report #14320

Qgis crashes when trying to add vector layer

Added by Philipp Ringli almost 9 years ago. Updated about 7 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Unknown
Affected QGIS version:2.12.1 Regression?:No
Operating System:OS X Easy fix?:No
Pull Request or Patch supplied:No Resolution:duplicate
Crashes QGIS or corrupts data:No Copied to github as #:22309

Description

If I run this script, Qgis crashes.

import os, processing
from unidecode import unidecode
import re
from qgis.core import *
from qgis.gui import *
import qgis.utils

def replaceChars(text):
    text = re.sub(r"[\\s+-]", "_", text.lower())
    text = re.sub(r"'", "", text)
    text = re.sub(r",", "_", text)
    text = unidecode(text)
    return text

crs = 'EPSG:3857' 
path = "/Users/cmyk/Desktop/Regionen/Frankreich/buffered" 

for lay in QgsMapLayerRegistry.instance().mapLayers().values():
    print(lay.name())
    if lay.name() == "buffered" :
        for z in lay.getFeatures():
            newName = (replaceChars(z["NAME_2"]))
            lay.setLayerName(newName)
            processing.runalg("qgis:reprojectlayer", lay, crs, path + "/" + newName)
            QgsMapLayerRegistry.instance().removeMapLayers( [lay.id()] )

            layer = QgsVectorLayer(path + "/" +  lay.name(), newName, "ogr")
            if not layer.isValid():
                print "Layer failed to load!" 

QGIS_2016-02-17-153943_wsPhil.crash (115 KB) Philipp Ringli, 2016-02-17 06:44 AM


Related issues

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

History

#1 Updated by Jürgen Fischer over 8 years ago

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

QgsMapLayerRegistry.instance().removeMapLayers( [lay.id()] ) deletes the layer so lay.name() will crash. This is a duplicate of #777

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

  • Category set to Unknown

Also available in: Atom PDF