qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.59k stars 3.01k forks source link

Error produced by closing algorithm dialogs: RuntimeError: wrapped C/C++ object of type QgsMapToolCapture has been deleted #53294

Closed AlisterH closed 1 year ago

AlisterH commented 1 year ago

What is the bug or the crash?

An error message is produced when closing a processing algorithm dialog, if the map tool that was active before opening the dialog is no longer available.

  1. The user should not be routinely exposed to an error message like this.
  2. I don't think the underlying behaviour is right, anyway. Presumably the code that is doing this was introduced to deal with situations where the user has clicked on something in the algorithm dialog that changes the map tool, e.g. to specify coordinates for an algorithm input. This code should only be run if such a map tool is still active. It should not be run if the user has not clicked on something in the algorithm dialog that changes the map tool, or if they have, but the map tool has then changed back to something else.

Steps to reproduce the issue

  1. View>Elevation Profile
  2. Click "Capture curve" button: image
  3. Launch a processing algorithm dialog.
  4. Close the Elevation Profile panel.
  5. Close the algorithm dialog
  6. QGIS produces an error message:
    
    2023-05-31T15:30:06     WARNING    Traceback (most recent call last):
              File "D:\OSGeo4W/apps/qgis-dev/./python/plugins\processing\ProcessingPlugin.py", line 406, in executeAlgorithm
              canvas.setMapTool(prevMapTool)
             RuntimeError: wrapped C/C++ object of type QgsMapToolCapture has been deleted```

Versions

Tested in 3.30.2 and a fairly recent nightly.



QGIS version
3.30.2-'s-Hertogenbosch
QGIS code revision
0992b533973
Qt version
5.15.3
Python version
3.9.5
GDAL/OGR version
3.7.0
PROJ version
9.2.0
EPSG Registry database version
v10.082 (2023-02-06)
GEOS version
3.11.2-CAPI-1.17.2
SQLite version
3.41.1
PDAL version
2.5.3
PostgreSQL client version
unknown
SpatiaLite version
5.0.1
QWT version
7.1.6
QScintilla2 version
2.13.1
OS version
Windows 10 Version 2009

Active Python plugins
annotationManager
0.5
annotation_labels
1.0.1
AnotherDXF2Shape
1.2.7
changeDataSource
3.1
civilplan
1.0
coveragebuilder
version 0.5.0
Equal_area_slope_QGIS_Plugin
0.1
file_management
0.1
FlowEstimator
0.21
geometry_paster
0.2
joinmultiplelines
Version 0.4.1
LayerBoard
1.0.1
layout_panel-main
0.3
MemoryLayerSaver
4.0.4
nominatim
1.4.5
pathfinder
version 0.4.2
plugin_reloader
0.9.3
precisioncursor4qgis-main
0.2E
QCopycanvas
0.7
qgis_resource_sharing
1.0.0
quick_map_services
0.19.33
StyleLoadSave
1.0
switch_active_layer
0.1
valuetool
3.0.15
workbench
0.0.4
db_manager
0.1.20
MetaSearch
0.3.6
processing
2.12.99
grassprovider
2.12.99

### Supported QGIS version

- [X] I'm running a supported QGIS version according to the roadmap.

### New profile

- [X] I tried with a new QGIS profile

### Additional context

_No response_
nicogodet commented 1 year ago

Same when running alg from locator

RuntimeError: wrapped C/C++ object of type QgsMapToolCapture has been deleted 
Traceback (most recent call last):
  File "C:\OSGeo4W/apps/qgis-dev/./python/plugins\processing\gui\AlgorithmLocatorFilter.py", line 128, in triggerResult
    canvas.setMapTool(prevMapTool)
RuntimeError: wrapped C/C++ object of type QgsMapToolCapture has been deleted
nicogodet commented 1 year ago

@alexbruy (For unknown reason, I can't comment on your PR...)

This pattern appears in other places :

https://github.com/qgis/QGIS/blob/29d1de4dff40f8854529ab334a3146445a87e4ca/python/plugins/processing/gui/AlgorithmLocatorFilter.py#L231

https://github.com/qgis/QGIS/blob/29d1de4dff40f8854529ab334a3146445a87e4ca/python/plugins/processing/gui/menus.py#L283