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.63k stars 3.01k forks source link

Freeze when snapping on WFS or OAPIF layer #51179

Open domi4484 opened 1 year ago

domi4484 commented 1 year ago

What is the bug or the crash?

Open the digitize tool or the vertex tool with snapping activated on a WFS layer makes the GUI freeze during indexing.

Additionally, trying to close QGIS during the freeze time makes it crash after some time (maybe at the end of indexing).

Peek 2022-12-12 05-54

Steps to reproduce the issue

  1. Open attached project WFS_Snapping.zip
  2. Start editing on the scratch layer
  3. Click on "Add Polygon Feature"

Versions

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

QGIS version | 3.24.1-Tisler | QGIS code branch | Release 3.24 -- | -- | -- | -- Qt version | 5.15.7 Python version | 3.10.8 GDAL/OGR version | 3.6.0 PROJ version | 9.1.1 EPSG Registry database version | v10.076 (2022-08-31) GEOS version | 3.11.1-CAPI-1.17.1 SQLite version | 3.40.0 PDAL version | 2.3.0 PostgreSQL client version | unknown SpatiaLite version | 5.0.1 QWT version | 6.2.0 QScintilla2 version | 2.13.3 OS version | openSUSE Tumbleweed   |   |   |   This copy of QGIS writes debugging output.   |   |   |   Active Python plugins document_management_system | dev linking_relation_editor | 1.1.0 gis-kt-zug_locator | 0.4.1 precipitation_plugin | dev trackable_project_files | v1.2.2 QgisModelBaker | dev solocator | dev qgis-maptiler-plugin | 3.1.1 qfieldsync | dev firstaid | 2.2.0 plugin_reloader | 0.9.2 quick_map_services | 0.19.32 ordered_relation_editor | dev MetaSearch | 0.3.6 db_manager | 0.1.20 grassprovider | 2.12.99 processing | 2.12.99 QGIS version 3.24.1-Tisler QGIS code branch [Release 3.24](https://github.com/qgis/QGIS/tree/release-3_24) Qt version 5.15.7 Python version 3.10.8 GDAL/OGR version 3.6.0 PROJ version 9.1.1 EPSG Registry database version v10.076 (2022-08-31) GEOS version 3.11.1-CAPI-1.17.1 SQLite version 3.40.0 PDAL version 2.3.0 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.2.0 QScintilla2 version 2.13.3 OS version openSUSE Tumbleweed This copy of QGIS writes debugging output. Active Python plugins document_management_system dev linking_relation_editor 1.1.0 gis-kt-zug_locator 0.4.1 precipitation_plugin dev trackable_project_files v1.2.2 QgisModelBaker dev solocator dev qgis-maptiler-plugin 3.1.1 qfieldsync dev firstaid 2.2.0 plugin_reloader 0.9.2 quick_map_services 0.19.32 ordered_relation_editor dev MetaSearch 0.3.6 db_manager 0.1.20 grassprovider 2.12.99 processing 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 Same happen on master
nicogodet commented 1 year ago

Looks like a long standing issue : https://github.com/qgis/QGIS/issues/22147, https://github.com/qgis/QGIS/issues/29465.

roya0045 commented 1 year ago

Should be an issue with any web source. The solution would be to have an indexing cache that only add what is displayed on screen and update it to include more when needed.

Though this problem has been reported multiple times already.

roya0045 commented 1 year ago

I'm looking into it, no garantess. But adding the map extent in the feture request during indexing doesn't seem to change much, thou I tested with esri rest feature service and it seems to want to process everything. Will check with the sample project if it helps.

Djedouas commented 2 weeks ago

After investigation, I found 2 causes for this issue.

  1. A bug when the snapping on intersections is enabled.
  2. A use case with a very long indexation time.

Here is what happens:

  1. The snapping is enabled, with snapping on intersection
  2. The cursor is moved in the map canvas
  3. The first indexation begins in a background thread
  4. A search for edges is made in the main thread to find intersections, and waits for the indexation to end -> QGIS freezes
  5. In my case, the timeout for waiting the end of the indexation is reached (30 sec)
  6. The indexation is forced to terminate while still computing and QGIS crashes

Point 6. should search for edges in "relaxed" mode so there is no freeze to wait for the indexation to finish, and we consider that no edge are found at this moment. As a result, the user can still use QGIS while the indexation status bar is showing the indexation running. For this I made PR https://github.com/qgis/QGIS/pull/59259

In the case of a quick indexation, when point 6 is reached it is already finished, or it freezes a very short time, so the bug was not detected.

For this use case, to accelerate the indexation, I propose to use another indexation strategy which is Extent. Here it is more efficient to only index what is inside the map canvas only, even if it means re-indexing every time the user moves the map. By accelerating the indexation, it will "bypass" the bug of the intersection snapping freeze.

Adding this python code as a project macro does the job:

from qgis.utils import iface
from qgis.core import QgsSnappingUtils

def openProject():
    iface.mapCanvas().snappingUtils().setIndexingStrategy(QgsSnappingUtils.IndexExtent)

def saveProject():
    pass

def closeProject():
    iface.mapCanvas().snappingUtils().setIndexingStrategy(QgsSnappingUtils.IndexHybrid)

You could also deactivate the intersection snapping if you don't need it until https://github.com/qgis/QGIS/pull/59259 is merged.