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

QGIS crash after loading WMS layer via script and zooming in and out #44095

Closed
pathmapper opened this issue Jul 9, 2021 · 11 comments
Closed
Assignees
Labels
Crash/Data Corruption Processing Relating to QGIS Processing framework or individual Processing algorithms

Comments

@pathmapper
Copy link
Contributor

Bug

QGIS crash after loading WMS layer via script and zooming in and out.

Steps to reproduce

  1. Execute the following script via the Processing Toolbox: script_for_crash.zip

  2. Quickly zoom in and out using the mouse scroll wheel.

Note: I'm aware that this is not the way to add a layer from a processing script but QGIS shouldn't crash anyway.

Report Details

Crash ID: 9313eccb44c59d5cc381054fb16f1e27ff672720

Stack Trace

QObject::property :
QMetaCallEvent::placeMetaCall :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
QEventDispatcherWin32::processEvents :
QEventLoop::exec :
QgsRasterDataProvider::block :
QgsSingleBandColorDataRenderer::block :
QgsBrightnessContrastFilter::block :
QgsHueSaturationFilter::block :
QgsRasterResampleFilter::block :
QgsRasterProjector::block :
QgsRasterIterator::readNextRasterPartInternal :
QgsRasterDrawer::draw :
QgsRasterLayerRenderer::render :
QgsMapRendererParallelJob::renderLayerStatic :
QgsArchive::zip :
QgsImageOperation::overlayColor :
QgsImageOperation::stackBlur :
QtConcurrent::ThreadEngineBase::run :
QThreadPoolPrivate::reset :
QThread::start :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.20.0-Odense
QGIS code revision: decaadb
Compiled against Qt: 5.15.2
Running against Qt: 5.15.2
Compiled against GDAL: 3.3.0
Running against GDAL: 3.3.0

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.18363

@pathmapper pathmapper added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jul 9, 2021
@gioman gioman added the Feedback Waiting on the submitter for answers label Jul 9, 2021
@gioman
Copy link
Contributor

gioman commented Jul 9, 2021

@pathmapper no crash here even if zooming/scrolling like crazy. 3.16 on Windows and master on Ubuntu 20.04.

@pathmapper
Copy link
Contributor Author

@gioman thanks for checking. I can reproduce it every time, maybe try zooming on different locations.

On Windows (stacktrace above) it's a fresh 3.20.0 install using the standalone installer.

Just tried it with master on Ubuntu 20.04 and it crashes also there:

master_on_ubuntu

Warning: QObject::setParent: Cannot set parent, new parent is in a different thread
Warning: QObject::connect: Cannot queue arguments of type 'QList<QgsMapLayer*>'
(Make sure 'QList<QgsMapLayer*>' is registered using qRegisterMetaType().)
Warning: QObject::connect: Cannot queue arguments of type 'QList<QgsMapLayer*>'
(Make sure 'QList<QgsMapLayer*>' is registered using qRegisterMetaType().)
QGIS died on signal 11Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 256
Aborted (core dumped)

@gioman
Copy link
Contributor

gioman commented Jul 9, 2021

Just tried it with master on Ubuntu 20.04 and it crashes also there:

@pathmapper can you test on a new QGIS profile?

@pathmapper
Copy link
Contributor Author

@gioman, sure, with the new profile there is no need to zoom, QGIS crashed right after executing the script:

master_on_ubuntu_2

@gioman gioman added the Processing Relating to QGIS Processing framework or individual Processing algorithms label Jul 9, 2021
@gioman
Copy link
Contributor

gioman commented Jul 9, 2021

let's see if others confirm.

@NyakudyaA
Copy link
Contributor

let's see if others confirm.

Tested on Ubuntu 20.04 with QGIS 3.20.0 and confirmed the crash happens without even zooming in and out

@gioman
Copy link
Contributor

gioman commented Jul 9, 2021

Tested on Ubuntu 20.04 with QGIS 3.20.0 and confirmed the crash happens without even zooming in and out

@NyakudyaA any chance you can test master?

@NyakudyaA
Copy link
Contributor

Tested on Ubuntu 20.04 with QGIS 3.20.0 and confirmed the crash happens without even zooming in and out

@NyakudyaA any chance you can test master?

I have tested on master and the issue still occurs

master

@gioman gioman added Crash/Data Corruption and removed Feedback Waiting on the submitter for answers labels Jul 22, 2021
@rouault rouault self-assigned this Sep 25, 2021
rouault added a commit to rouault/QGIS that referenced this issue Sep 25, 2021
…4095)

Otherwise when using QgsProject::addMapLayer() from Python, the
following warning is emitted:
```
Warning: QObject::connect: Cannot queue arguments of type 'QList<QgsMapLayer*>'
(Make sure 'QList<QgsMapLayer*>' is registered using qRegisterMetaType().)
```
rouault added a commit to rouault/QGIS that referenced this issue Sep 25, 2021
…4095)

Otherwise when using QgsProject::addMapLayer() from Python, the
following warning is emitted:
```
Warning: QObject::connect: Cannot queue arguments of type 'QList<QgsMapLayer*>'
(Make sure 'QList<QgsMapLayer*>' is registered using qRegisterMetaType().)
```
@rouault
Copy link
Contributor

rouault commented Sep 25, 2021

Some warning fixes in #45254
but the reason for the crash is in your script. Processing scripts are run in a dedicated thread, and it is thus unsafe to interact with global QGIS objects that live in the main thread.
If you add the following just after rlayer = QgsRasterLayer(urlWithParams, layername, 'wms') creation, it seems to solve the issue,

        from qgis.PyQt.QtWidgets import QApplication
        rlayer.moveToThread(QApplication.instance().thread())

but I wouldn't completely exclude the risk of multi-threading issues in the lines after. Actually all that code should be run in the main thread, probably using a one-time timer attached to the main thread

So this is mostly a "the qgis python API is just an access to the underlying C++ world, but all the complex rules of Qt still apply, and you can easily shoot yourself in the foot"

@rouault rouault removed the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 25, 2021
@nyalldawson
Copy link
Collaborator

Just to add to @rouault 's answer -- you can make your algorithm return the "FlagNoThreading" flag to force.it to run in that main thread and avoid these issues.

@pathmapper
Copy link
Contributor Author

@rouault @nyalldawson thanks for explaining the backgound and the hints !

espinafre pushed a commit to espinafre/QGIS that referenced this issue Sep 29, 2021
…4095)

Otherwise when using QgsProject::addMapLayer() from Python, the
following warning is emitted:
```
Warning: QObject::connect: Cannot queue arguments of type 'QList<QgsMapLayer*>'
(Make sure 'QList<QgsMapLayer*>' is registered using qRegisterMetaType().)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash/Data Corruption Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

No branches or pull requests

5 participants