summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 d57f5cf98e..e55119f9fd 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));
}