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

Calling a Processing algorithm by instance from plugin makes QGIS crash #51971

Closed
2 tasks done
ghtmtt opened this issue Feb 22, 2023 · 9 comments · Fixed by #51985
Closed
2 tasks done

Calling a Processing algorithm by instance from plugin makes QGIS crash #51971

ghtmtt opened this issue Feb 22, 2023 · 9 comments · Fixed by #51985
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption PyQGIS Related to the PyQGIS API

Comments

@ghtmtt
Copy link
Contributor

ghtmtt commented Feb 22, 2023

What is the bug or the crash?

With a plugin with both standard interface and Processing Provider, if, from the interface a Processing algorithm is called with the createAlgorithmDialog method this happens:

  • by passing the algorithm group:name as first argument, it works nice
  • by passing the algorithm instance QGIS is crashing (seems a thread problem)

By reading the documentation of the createAlgorithmDialog method, it seems that we should be able to use both name or instance.

I've prepared a plugin (can be installed directly with the zip) , created with the Plugin Builder, that you can use to test this behavior. crash.zip.

It does not have any real logic but the crash is happening. The Processing algorithm is the same as the Script from template. The crash is happening in the crash_dialog.py file, line 57, where the algorithm dialog is created using the instance of the algorithm. The commented lines from the 62 will do the same but with the algorithm name (working fine).

Steps to reproduce the issue

  • install the plugin from the zip provided
  • click on the plugin icon
  • click on the OK button

Versions

From QGIS 3.22 to QGIS master

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

This is the StackTrace when clicking on OK that makes QGIS crash:

Python Stack Trace
Fatal Python error: Segmentation fault

Current thread 0x00007f1ae4deb800 (most recent call first):
  File "/home/matteo/dev/qgis-master/output/python/plugins/processing/gui/AlgorithmDialog.py", line 70 in __init__
    self.setAlgorithm(alg)
  File "/home/matteo/dev/qgis-master/output/python/plugins/processing/tools/general.py", line 178 in createAlgorithmDialog
    dlg = AlgorithmDialog(alg, parent=iface.mainWindow())
  File "/home/matteo/.local/share/QGIS/QGIS3/profiles/matteo/python/plugins/crash/crash_dialog.py", line 57 in runProcessing
    dialog = processing.createAlgorithmDialog(
  File "/home/matteo/.local/share/QGIS/QGIS3/profiles/matteo/python/plugins/crash/crash.py", line 212 in run
    result = self.dlg.exec_()

Extension modules: PyQt5.QtCore, PyQt5.QtGui, PyQt5.QtWidgets, PyQt5.QtPrintSupport, PyQt5.Qsci, PyQt5.QtNetwork, PyQt5.QtMultimedia, PyQt5.QtXml, PyQt5.QtPositioning, PyQt5.QtSql, qgis._core, qgis._gui, _brotli, simplejson._speedups, qgis._analysis, osgeo._gdal, osgeo._gdalconst, osgeo._ogr, osgeo._osr, psycopg2._psycopg, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, pandas._libs.tslibs.np_datetime, pandas._libs.tslibs.dtypes, pandas._libs.tslibs.base, pandas._libs.tslibs.nattype, pandas._libs.tslibs.timezones, pandas._libs.tslibs.tzconversion, pandas._libs.tslibs.ccalendar, pandas._libs.tslibs.fields, pandas._libs.tslibs.timedeltas, pandas._libs.tslibs.timestamps, pandas._libs.properties, pandas._libs.tslibs.offsets, pandas._libs.tslibs.parsing, pandas._libs.tslibs.conversion, pandas._libs.tslibs.period, pandas._libs.tslibs.vectorized, pandas._libs.ops_dispatch, pandas._libs.missing, pandas._libs.hashtable, pandas._libs.algos, pandas._libs.interval, pandas._libs.tslib, pandas._libs.lib, pandas._libs.hashing, pandas._libs.ops, numexpr.interpreter, bottleneck.move, bottleneck.nonreduce, bottleneck.nonreduce_axis, bottleneck.reduce, pandas._libs.arrays, pandas._libs.index, pandas._libs.join, pandas._libs.sparse, pandas._libs.reduction, pandas._libs.indexing, pandas._libs.internals, pandas._libs.writers, pandas._libs.window.aggregations, pandas._libs.window.indexers, pandas._libs.reshape, pandas._libs.tslibs.strptime, pandas._libs.groupby, pandas._libs.testing, pandas._libs.parsers, pandas._libs.json, matplotlib._c_internal_utils, PIL._imaging, matplotlib._path, kiwisolver._cext, matplotlib._image, PyQt5.QtWebKit, PyQt5.QtWebKitWidgets, PyQt5.QtTest, PyQt5.QtSvg, PyQt5.QtLocation, PyQt5.QtOpenGL, PyQt5.QtMultimediaWidgets, PyQt5.QtHelp, PyQt5.QtDesigner, PyQt5.QtDBus (total: 94)


Stack Trace
No stack trace is available.


QGIS Info
QGIS Version: 3.29.0-Master
QGIS code revision: 955c9017bb
Compiled against Qt: 5.15.8
Running against Qt: 5.15.8
Compiled against GDAL: 3.6.2
Running against GDAL: 3.6.2



System Info
CPU Type: x86_64
Kernel Type: linux
Kernel Version: 6.1.0-5-amd64
@ghtmtt ghtmtt added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Feb 22, 2023
@agiudiceandrea agiudiceandrea added PyQGIS Related to the PyQGIS API Crash/Data Corruption labels Feb 22, 2023
@gacarrillor
Copy link
Member

You need to set a provider for your algorithm, in this way:

crash_alg = CrashProcessingAlgorithm()
crash_alg.setProvider(QgsApplication.processingRegistry().providerById('crash'))

dialog = processing.createAlgorithmDialog(crash_alg)

However, this shouldn't crash.
@nyalldawson, would it be OK if I add an if inside both createAlgorithmDialog() and execAlgorithmDialog() to avoid calling AlgorithmDialog() with an alg that has no provider OR should we return a None from AlgorithmDialog() when it's called with an alg that has no provider?

@nyalldawson
Copy link
Collaborator

@gacarrillor

Ideally the provider shouldn't be mandatory -- I'll see if it's trivial to make it optional.

@ghtmtt
Copy link
Contributor Author

ghtmtt commented Feb 23, 2023

@gacarrillor I replaced my code with yours but it still crashing, same type of crash.

Were you able to make it work without crashing?

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Feb 23, 2023

@ghtmtt id does not crash in my Windows system, just adding
from qgis.core import QgsApplication
and substituting

        dialog = processing.createAlgorithmDialog(
            CrashProcessingAlgorithm()
        )

with

        crash_alg = CrashProcessingAlgorithm()
        crash_alg.setProvider(QgsApplication.processingRegistry().providerById('crash'))
        dialog = processing.createAlgorithmDialog(
            crash_alg
        )

@ghtmtt
Copy link
Contributor Author

ghtmtt commented Feb 23, 2023

yeah, that's exactly what I did, but it is still crashing on my Linux.

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Feb 23, 2023

Maybe you need to remove the __pycache__ folder so the .pyc files will be regenerated.

@ghtmtt
Copy link
Contributor Author

ghtmtt commented Feb 23, 2023

ohh correct, thanks! Now it is working.

@gacarrillor
Copy link
Member

@gacarrillor

Ideally the provider shouldn't be mandatory -- I'll see if it's trivial to make it optional.

@nyalldawson, much better 👍

@ghtmtt
Copy link
Contributor Author

ghtmtt commented Feb 23, 2023

tested the master with the PR, works as expected. Love you guys :)

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 PyQGIS Related to the PyQGIS API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants