[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.
This commit is contained in:
@@ -61,6 +61,12 @@ const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"M
|
||||
|
||||
- (void)addToMapView:(MGLMapView *)mapView
|
||||
{
|
||||
if (_pendingSource == nullptr) {
|
||||
[NSException raise:@"MGLRedundantSourceException"
|
||||
format:@"This instance %@ was already added to %@. Adding the same source instance " \
|
||||
"to the style more than once is invalid.", self, mapView.style];
|
||||
}
|
||||
|
||||
mapView.mbglMap->addSource(std::move(_pendingSource));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user