From 1db0a96927d53bc0216d48cf5add1254ae6cab89 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 1 Dec 2016 21:20:53 -0800 Subject: [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 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. --- platform/darwin/src/MGLStyleLayer.mm.ejs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'platform/darwin/src/MGLStyleLayer.mm.ejs') diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 85a1af9970..c89912c1ff 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -112,6 +112,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]; } -- cgit v1.2.1