Bug report #14320

Qgis crashes when trying to add vector layer

Added by Philipp Ringli almost 2 years ago. Updated 2 months 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

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, 02/17/2016 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 1 year 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 2 months ago

  • Category set to Unknown

Also available in: Atom PDF