Bug report #10096
QGIS crashes when QgsRendererV2.symbolForFeature() is called from Python
Status: | Closed | ||
---|---|---|---|
Priority: | Severe/Regression | ||
Assignee: | - | ||
Category: | - | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | fixed/implemented |
Crashes QGIS or corrupts data: | Yes | Copied to github as #: | 18564 |
Description
With graduated styled layer, the following code crashes QGIS. It works in 2.2 without any problems.
layer = iface.activeLayer() renderer = layer.rendererV2() f = QgsFeature() layer.getFeatures().nextFeature(f) s = renderer.symbolForFeature(f)
With categorized styled layer, symbolForFeature() returns None. It returns a subclass object of QgsSymbolV2 correctly in 2.2.
Crash doesn't seem to occur if the graduated styled layer has been loaded through a project file, and a subclass object of QgsSymbolV2 is returned correctly, but with categorized styled layer, it still returns None.
This method is useful for plugins which export data with styles.
Associated revisions
fix categorized renderer crash (fixes #10096)
History
#1 Updated by Matthias Kuhn over 10 years ago
As a workaround for the crash: embed your calls within `renderer.startRender()` and `renderer.stopRender()` to have the renderer in a state where it is able to evaluate expressions.
In the long term it would however be nice to have somebody who knows this code to have a look at the lifetime of the expression which crashes.
#2 Updated by Minoru Akagi over 10 years ago
Matthias Kuhn wrote:
As a workaround for the crash: embed your calls within `renderer.startRender()` and `renderer.stopRender()` to have the renderer in a state where it is able to evaluate expressions.
Works fine with the workaround. Thanks, Matthias!
#3 Updated by Jürgen Fischer over 10 years ago
- Status changed from Open to Closed
Fixed in changeset dcc9d39a273eebc54f996af088daca23b31c0efb.
#4 Updated by Alexander Bruy over 10 years ago
- Status changed from Closed to Reopened
Still true in latest master.
Seems this method does not work as expected for almost all renderers:- QgsSingleSymbolRendererV2 — returns feature symbol
- QgsCategorizedSymbolRendererV2 — returns None and in debug output I have message saying "there are no hashed symbols!!!"
- QgsGraduatedSymbolRendererV2 — just crashes QGIS
- QgsRuleBasedRendererV2 — returns None
Tested with point shapefile and same code as in initial post.
#5 Updated by Matthias Kuhn over 10 years ago
- Status changed from Reopened to Feedback
I think the workaround should be accepted as solution and stated in the API documentation according to [1]
The only thing left to fix is the crash in graduatedsymbolrenderer. The last "fix" was also just about the crash and not about changing the behavior to be compatible with calls out of startRender() / stopRender() context.
[1] http://permalink.gmane.org/gmane.comp.gis.qgis.devel/32841
#6 Updated by Matthias Kuhn over 10 years ago
- Resolution set to fixed/implemented
- Status changed from Feedback to Closed
No crash here.
If it's still reproducable, please reopen.