diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-07-12 17:01:49 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-07-13 14:59:45 +0300 |
commit | bb1a209a6396dd5d41651092b354607b6852c0c8 (patch) | |
tree | 3501b46d218d232fe7d342050013abb7a222fb68 /platform | |
parent | d0be2ed2a6876226c99591ddf1cde0f9fc85580c (diff) | |
download | qtlocation-mapboxgl-bb1a209a6396dd5d41651092b354607b6852c0c8.tar.gz |
[Qt] Share the DefaultFileSource for all QMapboxGL instances
Fix issues of concurrent access to the sqlite cache.
Fixes #9108.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 20 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_p.hpp | 2 |
2 files changed, 20 insertions, 2 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index eafc06c028..543a8bf2d6 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -70,6 +70,19 @@ namespace { QThreadStorage<std::shared_ptr<mbgl::util::RunLoop>> loop; +std::shared_ptr<mbgl::DefaultFileSource> sharedDefaultFileSource( + const std::string& cachePath, const std::string& assetRoot, uint64_t maximumCacheSize) { + static std::weak_ptr<mbgl::DefaultFileSource> weak; + auto fs = weak.lock(); + + if (!fs) { + weak = fs = std::make_shared<mbgl::DefaultFileSource>( + cachePath, assetRoot, maximumCacheSize); + } + + return fs; +} + // Conversion helper functions. mbgl::Size sanitizedSize(const QSize& size) { @@ -106,6 +119,11 @@ std::unique_ptr<mbgl::style::Image> toStyleImage(const QString &id, const QImage QMapboxGLSettings is used to configure QMapboxGL at the moment of its creation. Once created, the QMapboxGLSettings of a QMapboxGL can no longer be changed. + Cache-related settings are shared between all QMapboxGL instances because different + maps will share the same cache database file. The first map to configure cache properties + such as size and path will force the configuration to all newly instantiated QMapboxGL + objects. + \since 4.7 */ @@ -1473,7 +1491,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin : QObject(q) , size(size_) , q_ptr(q) - , fileSourceObj(std::make_unique<mbgl::DefaultFileSource>( + , fileSourceObj(sharedDefaultFileSource( settings.cacheDatabasePath().toStdString(), settings.assetPath().toStdString(), settings.cacheDatabaseMaximumSize())) diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp index 49a7942cce..3c8a6cf09e 100644 --- a/platform/qt/src/qmapboxgl_p.hpp +++ b/platform/qt/src/qmapboxgl_p.hpp @@ -52,7 +52,7 @@ public: QMapboxGL *q_ptr { nullptr }; - std::unique_ptr<mbgl::DefaultFileSource> fileSourceObj; + std::shared_ptr<mbgl::DefaultFileSource> fileSourceObj; std::shared_ptr<mbgl::ThreadPool> threadPool; std::unique_ptr<mbgl::Map> mapObj; |