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

Tile download manager [grant 2020] #40998

Merged
merged 8 commits into from
Jan 20, 2021

Conversation

wonder-sk
Copy link
Member

@wonder-sk wonder-sk commented Jan 13, 2021

qgis/QGIS-Enhancement-Proposals#181

Currently used for vector tiles only.

@wonder-sk wonder-sk marked this pull request as draft January 13, 2021 22:19
src/core/qgstiledownloadmanager.h Outdated Show resolved Hide resolved
src/core/qgstiledownloadmanager.h Outdated Show resolved Hide resolved
Comment on lines +133 to +137
* - Upon a request, a QgsTileDownloadManagerReply object (based on QObject) is returned,
* encapsulating the pending reply. Client can wait for its finished() signal - when
* it gets emitted, the request has finished with success or failure. Client can delete
* the reply object before the request is processed - download manager will finish its
* download (and it will get cached for a future use).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question -- how would a renderer operating on the main thread (eg layout map exports) safely use this? From my interpretation this process implies use of an event loop to wait until the finished signal can be emitted, which isn't safe to do in this circumstance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure there is a safe way to have renderers run in the main thread and doing some async network requests at the same time. As you say, that implies having an event loop to wait for signals, and other GUI events could cause havoc.

The tile download manager is nearly a drop-in replacement for direct use of QNetworkRequest - the behavior is meant to be the same with the finished() signal, so there should be no change in this regard (not making things better nor worse).

I guess to make things safe one would need to use some other means of thread synchronization instead of signals and event loops, or some horrible hacks like adding an event filter on the embedded event loop, "stealing" the events we don't want to deal with, and then posting them back after the event loop has finished :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's the QgsBlockingNetworkRequest class which was designed for use by providers to handle this situation gracefully (it uses no event loops on the main thread).

This change doesn't make the situation any worse regarding this issue, but it also doesn't help and at some point in the future I think we're going to have to address this properly and ban all event loops/processEvent calls from the data providers. That's why I'd have loved to see this considered in the design on the tile cache...

@github-actions github-actions bot added this to the 3.18.0 milestone Jan 13, 2021
@wonder-sk wonder-sk marked this pull request as ready for review January 15, 2021 13:49
@nyalldawson nyalldawson added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 15, 2021
src/core/qgsapplication.h Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.h Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.h Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.cpp Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.cpp Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.cpp Outdated Show resolved Hide resolved
src/core/vectortile/qgsvectortileloader.cpp Outdated Show resolved Hide resolved
src/core/qgstiledownloadmanager.h Show resolved Hide resolved
};


/// @cond PRIVATE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: wouldn't it be better to move all these private classes to new qgstiledownloadmanager_p.h/cpp files?

src/core/qgstiledownloadmanager.h Show resolved Hide resolved
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants