Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS crashes when QgsRendererV2.symbolForFeature() is called from Python #18564

Closed
qgib opened this issue Apr 21, 2014 · 6 comments
Closed

QGIS crashes when QgsRendererV2.symbolForFeature() is called from Python #18564

qgib opened this issue Apr 21, 2014 · 6 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption

Comments

@qgib
Copy link
Contributor

qgib commented Apr 21, 2014

Author Name: Minoru Akagi (@minorua)
Original Redmine Issue: 10096
Affected QGIS version: master


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.


@qgib
Copy link
Contributor Author

qgib commented Apr 21, 2014

Author Name: Matthias Kuhn (@m-kuhn)


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.

@qgib
Copy link
Contributor Author

qgib commented Apr 21, 2014

Author Name: Minoru Akagi (@minorua)


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!

@qgib
Copy link
Contributor Author

qgib commented Jun 1, 2014

Author Name: Jürgen Fischer (@jef-n)


Fixed in changeset "dcc9d39a273eebc54f996af088daca23b31c0efb".


  • status_id was changed from Open to Closed

@qgib
Copy link
Contributor Author

qgib commented Jul 3, 2014

Author Name: Alexander Bruy (@alexbruy)


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.


  • status_id was changed from Closed to Reopened

@qgib
Copy link
Contributor Author

qgib commented Jul 23, 2014

Author Name: Matthias Kuhn (@m-kuhn)


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


  • status_id was changed from Reopened to Feedback

@qgib
Copy link
Contributor Author

qgib commented Jul 24, 2014

Author Name: Matthias Kuhn (@m-kuhn)


No crash here.
If it's still reproducable, please reopen.


  • resolution was changed from to fixed/implemented
  • status_id was changed from Feedback to Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption
Projects
None yet
Development

No branches or pull requests

1 participant