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.52k stars 2.99k forks source link

QgsMeshLayer does not release file lock after removing layer #44474

Closed Huite closed 1 year ago

Huite commented 3 years ago

What is the bug or the crash?

I've been interacting with some UGRID netCDFs via QGIS. When removing a layer from QGIS (via layers panel or PyQGIS), this does not seem to release the file lock: when I e.g. try to delete the file, I get a message "access denied on file".

I've done a little bit of testing with some of the test files in the MDAL repository. I haven't tested exhaustively, but it seems to turn up only on the formats utilizing netCDF specifically. So I cannot delete UGRID files, Tuflow files even after removing the layers. The GRIB file (wind_only_u_component.grib) gives no problems.

Interestingly, adding a different file which requires the same driver seems to free the file again.

Steps to reproduce the issue

  1. Download a netCDF based mesh file, e.g.:

https://github.com/lutraconsulting/MDAL/blob/master/tests/data/ugrid/D-Flow1.2/bw_11_zonder_riviergrid_met_1dwtg_clm.nc

and:

https://github.com/lutraconsulting/MDAL/blob/master/tests/data/tuflowfv/withMaxes/trap_steady_05_3D.nc

  1. Add the file as a Mesh Layer in QGIS.

  2. Remove the file via the Layers Panel > Remove Layers.

  3. Open file manager, and try to delete the downloaded file.

  4. Add another file which requires the same driver (copy one of the above files if needed).

  5. Go back to file manager, and try to delete the file once more.

Versions

I get the same behavior on 3.16, 3.18 and 3.20.

``` QGIS version 3.20.1-Odense QGIS code revision 1c3c5cd6 Qt version 5.15.2 Python version 3.9.5 GDAL/OGR version 3.3.1 PROJ version 8.1.0 EPSG Registry database version v10.018 (2021-04-02) GEOS version 3.9.1-CAPI-1.14.2 SQLite version 3.35.2 PDAL version 2.3.0 PostgreSQL client version 13.0 SpatiaLite version 5.0.1 QWT version 6.1.3 QScintilla2 version 2.11.5 OS version Windows 10 Version 1909 Active Python plugins gmsh pdokservicesplugin pluginbuilder3 plugin_reloader profiletool Serval valuetool ```

Additional context

No response

roya0045 commented 3 years ago

@PeterPetrik Hi Peter, do you know if this could be related to MDAL specifically or its integration in qgis?

gioman commented 3 years ago

Seems to be the case only on Windows.

PeterPetrik commented 3 years ago

This could be problem in either QGIS (not calling MDAL_CloseMesh appropriately) or MDAL (some issue with MDAL_CloseMesh for netCDF driver). Thanks for very good bug description, I will try to look before next release

vcloarec commented 2 years ago

MDAL issue fixed by https://github.com/lutraconsulting/MDAL/pull/426

I will close this issue when new MDAL release will be imported in QGIS master.

alexbruy commented 1 year ago

Works fine in latest master (3642c9cc40).