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/MGLStyle.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'platform/darwin/src/MGLStyle.h') diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 10fad0196e..31808290f9 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -200,6 +200,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new source to the current style. + @note Adding the same source instance more than once or reusing source + identifers in the sources you add will trigger exceptions. + @param source The source to add to the current style. */ - (void)addSource:(MGLSource *)source; @@ -247,6 +250,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new layer on top of existing layers. + @note Adding the same layer instance more than once or reusing layer + identifers in the layers you add will trigger exceptions. + @param layer The layer object to add to the map view. This object must be an instance of a concrete subclass of `MGLStyleLayer`. */ @@ -255,6 +261,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Inserts a new layer into the style at the given index. + @note Adding the same layer instance more than once or reusing layer + identifers in the layers you add will trigger exceptions. + @param layer The layer to insert. @param index The index at which to insert the layer. An index of 0 would send the layer to the back; an index equal to the number of objects in the @@ -272,6 +281,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; inspectable in Interface Builder, or a manually constructed `NSURL`. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time. + + Adding the same layer instance more than once or reusing layer identifers in + the layers you add will trigger exceptions. @param layer The layer to insert. @param sibling An existing layer in the style. @@ -288,6 +300,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; inspectable in Interface Builder, or a manually constructed `NSURL`. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time. + + Adding the same layer instance more than once or reusing layer identifers in + the layers you add will trigger exceptions. @param layer The layer to insert. @param sibling An existing layer in the style. -- cgit v1.2.1