From bb1a209a6396dd5d41651092b354607b6852c0c8 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 12 Jul 2017 17:01:49 +0300 Subject: [Qt] Share the DefaultFileSource for all QMapboxGL instances Fix issues of concurrent access to the sqlite cache. Fixes #9108. --- platform/qt/src/qmapboxgl.cpp | 20 +++++++++++++++++++- platform/qt/src/qmapboxgl_p.hpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'platform') 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> loop; +std::shared_ptr sharedDefaultFileSource( + const std::string& cachePath, const std::string& assetRoot, uint64_t maximumCacheSize) { + static std::weak_ptr weak; + auto fs = weak.lock(); + + if (!fs) { + weak = fs = std::make_shared( + cachePath, assetRoot, maximumCacheSize); + } + + return fs; +} + // Conversion helper functions. mbgl::Size sanitizedSize(const QSize& size) { @@ -106,6 +119,11 @@ std::unique_ptr 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( + , 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 fileSourceObj; + std::shared_ptr fileSourceObj; std::shared_ptr threadPool; std::unique_ptr mapObj; -- cgit v1.2.1