diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-12-01 21:20:53 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-12-02 14:21:05 -0800 |
commit | 1db0a96927d53bc0216d48cf5add1254ae6cab89 (patch) | |
tree | 43625af30467a433cde87ed03ee76768cfd3fd95 /platform/darwin/src/MGLFillStyleLayer.mm | |
parent | 2db31be8bc0130ac2f02bc2245b1ff21103e9baf (diff) | |
download | qtlocation-mapboxgl-1db0a96927d53bc0216d48cf5add1254ae6cab89.tar.gz |
[ios, macos] Raise NSException if layer or source added more than once
When MGLSource and MGLLayer instances are added to the style, they lose
ownership of their std::unique_ptr<T> after it is moved to the mbgl
level. Subsequent attempts to add such instances result in a C++
exception.
This adds logic in the Darwin platform to raise a NSException if the
source and layer addToMapView methods are called more than once and the
pointer is invalid. In addition, the documentation in MGLStyle for
addSource: and addLayer: has been update to warn developers to avoid
adding the same instance twice and, for that matter, instances with the
same identifier.
Diffstat (limited to 'platform/darwin/src/MGLFillStyleLayer.mm')
-rw-r--r-- | platform/darwin/src/MGLFillStyleLayer.mm | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index d1a96f7230..87a5144c6b 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -70,6 +70,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } |