summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-11-28 17:35:10 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2016-11-30 19:35:29 +0200
commit60e451174fc1b7100e97f9f7aa2d0766f8fa8389 (patch)
tree0b7f1aaa460804c5413c4d9941885931d220afb9 /src/mbgl/style
parent13b7b3a92b6e4fd88c78b61904abdf87e4903adf (diff)
downloadqtlocation-mapboxgl-60e451174fc1b7100e97f9f7aa2d0766f8fa8389.tar.gz
[core] guard against duplicate source id’s
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/style.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 867a03da79..44843ce8b7 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -136,6 +136,16 @@ void Style::setJSON(const std::string& json) {
}
void Style::addSource(std::unique_ptr<Source> source) {
+ //Guard against duplicate source ids
+ auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& existing) {
+ return existing->getID() == source->getID();
+ });
+
+ if (it != sources.end()) {
+ std::string msg = "Source " + source->getID() + " already exists";
+ throw std::runtime_error(msg.c_str());
+ }
+
source->baseImpl->setObserver(this);
sources.emplace_back(std::move(source));
}