summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2017-06-09 12:05:54 +0200
committerGitHub <noreply@github.com>2017-06-09 12:05:54 +0200
commit6ec5e4f8cdb98227db11e5989376c31832ca2048 (patch)
tree666de95e35b73f4c6f851e9c243c29fe74ce4465 /src
parentfa972fad60e58e5b8f9f9622f508e9732c8c9ffd (diff)
downloadqtlocation-mapboxgl-6ec5e4f8cdb98227db11e5989376c31832ca2048.tar.gz
Cherry picks to release branch (#9230)
* [ios][macos] test remove source in use * [android] test remove source in use * [core] check source usage before remove * [core] ensure layer::accept works with non-void return values on gcc * [android] - remove upgrade runtime exceptions (#9191)
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/style.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index f083ca47b8..568b575dfa 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -196,7 +196,30 @@ void Style::addSource(std::unique_ptr<Source> source) {
sources.emplace_back(std::move(source));
}
+struct SourceIdUsageEvaluator {
+ const std::string& sourceId;
+
+ bool operator()(BackgroundLayer&) { return false; }
+ bool operator()(CustomLayer&) { return false; }
+
+ template <class LayerType>
+ bool operator()(LayerType& layer) {
+ return layer.getSourceID() == sourceId;
+ }
+};
+
std::unique_ptr<Source> Style::removeSource(const std::string& id) {
+ // Check if source is in use
+ SourceIdUsageEvaluator sourceIdEvaluator {id};
+ auto layerIt = std::find_if(layers.begin(), layers.end(), [&](const auto& layer) {
+ return layer->accept(sourceIdEvaluator);
+ });
+
+ if (layerIt != layers.end()) {
+ Log::Warning(Event::General, "Source '%s' is in use, cannot remove", id.c_str());
+ return nullptr;
+ }
+
auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
return source->getID() == id;
});