summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2017-02-20 15:06:46 -0800
committerJesse Bounds <jesse@rebounds.net>2017-02-23 15:07:43 -0800
commitc0718a863d0a915641857bc9cd4ff51cd508f222 (patch)
tree0d63485afba44e45d4dbb21492d25a36591f7089
parente860fa6f0a71805dafd03a1ac02980369b799f9e (diff)
downloadqtlocation-mapboxgl-c0718a863d0a915641857bc9cd4ff51cd508f222.tar.gz
[core, ios, macos] Return null when removing nonexistent source
-rw-r--r--platform/darwin/src/MGLRasterSource.mm6
-rw-r--r--platform/darwin/src/MGLShapeSource.mm6
-rw-r--r--platform/darwin/src/MGLVectorSource.mm6
-rw-r--r--platform/darwin/test/MGLStyleTests.mm17
-rw-r--r--src/mbgl/style/style.cpp2
5 files changed, 30 insertions, 7 deletions
diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm
index ccd5212b2a..9f1d035994 100644
--- a/platform/darwin/src/MGLRasterSource.mm
+++ b/platform/darwin/src/MGLRasterSource.mm
@@ -84,8 +84,10 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512;
- (void)removeFromMapView:(MGLMapView *)mapView {
auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
- _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource));
- self.rawSource = _pendingSource.get();
+ if (removedSource) {
+ _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource));
+ self.rawSource = _pendingSource.get();
+ }
}
- (mbgl::style::RasterSource *)rawSource {
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm
index 07033d8d45..d7d26ba36d 100644
--- a/platform/darwin/src/MGLShapeSource.mm
+++ b/platform/darwin/src/MGLShapeSource.mm
@@ -88,8 +88,10 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh
- (void)removeFromMapView:(MGLMapView *)mapView {
auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
- _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource));
- self.rawSource = _pendingSource.get();
+ if (removedSource) {
+ _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource));
+ self.rawSource = _pendingSource.get();
+ }
}
- (mbgl::style::GeoJSONSource *)rawSource {
diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm
index a16cfa6d81..840382913d 100644
--- a/platform/darwin/src/MGLVectorSource.mm
+++ b/platform/darwin/src/MGLVectorSource.mm
@@ -58,8 +58,10 @@
- (void)removeFromMapView:(MGLMapView *)mapView {
auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
- _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource));
- self.rawSource = _pendingSource.get();
+ if (removedSource) {
+ _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource));
+ self.rawSource = _pendingSource.get();
+ }
}
- (mbgl::style::VectorSource *)rawSource {
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 7939db576e..86cf11d4aa 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -174,6 +174,23 @@
XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentifierException");
}
+- (void)testRemovingSourcesBeforeAddingThem {
+ MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"raster-source" tileURLTemplates:@[] options:nil];
+ [self.style removeSource:rasterSource];
+ [self.style addSource:rasterSource];
+ XCTAssertNotNil([self.style sourceWithIdentifier:rasterSource.identifier]);
+
+ MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source" shape:nil options:nil];
+ [self.style removeSource:shapeSource];
+ [self.style addSource:shapeSource];
+ XCTAssertNotNil([self.style sourceWithIdentifier:shapeSource.identifier]);
+
+ MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vector-source" tileURLTemplates:@[] options:nil];
+ [self.style removeSource:vectorSource];
+ [self.style addSource:vectorSource];
+ XCTAssertNotNil([self.style sourceWithIdentifier:vectorSource.identifier]);
+}
+
- (void)testLayers {
NSArray<MGLStyleLayer *> *initialLayers = self.style.layers;
if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) {
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 0119dd3d8d..b6f14ecf4b 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -159,7 +159,7 @@ std::unique_ptr<Source> Style::removeSource(const std::string& id) {
});
if (it == sources.end()) {
- throw std::runtime_error("no such source");
+ return nullptr;
}
auto source = std::move(*it);