Bug report #15715
Segmentation fault on exit when using a QgsMapTool
|Affected QGIS version:||2.16.3||Regression?:||No|
|Operating System:||Ubuntu||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||invalid|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||23638|
When using pyqgis in a custom application, there is a Segmentation fault crash upon exiting the application after app.exitQGis() call when the programm exists. It appears on exit as soon as during lifetime of the application a QgsMapToolPan (as in example) is created. During application lifetime itself, there are no problems.
#1 Updated by Martin Dobias almost 5 years ago
- Resolution set to invalid
- Status changed from Open to Closed
It looks like your "gui" variable with canvas and a map tool still lives when QGIS libs have been already uninitialized. That means when cleaning up the "gui" variable you get the crash. A simple fix should be to delete "gui" before calling exitQgis(). Or just put all handling of "gui" variable into a function, so it gets out of scope before exitQgis():
def run_app(app): gui = GUI() gui.show() app.exec_() qgsapp.initQgis() run_app(qgsapp) qgsapp.exitQgis()
#2 Updated by Uros Bernik almost 5 years ago
Yes, i've seen this suggested: http://gis.stackexchange.com/questions/206523/segmentation-fault-upon-exit-of-qgis-map-canvas
The error still occurs, even with the aux function implementation, the problematic line is the creation of a pan tool, more precisely, if a pan tool instance is stored into a gui instance variable.
If it's just created in the construcor then set as the current tool, there is no segfault on exit:
For the moment, im unsetting the GUI instance variable at window close, which also works.