diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-11-28 17:35:10 +0200 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-12-02 11:25:30 -0800 |
commit | 2c4e7ae70f68eecf56707f0ebd9810340f41e6a3 (patch) | |
tree | 5a62004e9238cb329d7ec7bd050c2180960a44c2 /src/mbgl/style/style.cpp | |
parent | 8317a11a10400c28e36017a9441e18d49f99acd0 (diff) | |
download | qtlocation-mapboxgl-2c4e7ae70f68eecf56707f0ebd9810340f41e6a3.tar.gz |
[core] guard against duplicate source id’s
Diffstat (limited to 'src/mbgl/style/style.cpp')
-rw-r--r-- | src/mbgl/style/style.cpp | 10 |
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)); } |