diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-09-04 15:17:44 +0300 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2019-09-07 00:15:38 -0400 |
commit | 365c38b9ccbe0dab3a2542a504f30d1646a6c325 (patch) | |
tree | 3c2cd344f20be91667b2a02e1bd668fc95b5f9c5 | |
parent | 56ccc5ad6b7cb737c0721008ca6ae21ec580d2f6 (diff) | |
download | qtlocation-mapboxgl-365c38b9ccbe0dab3a2542a504f30d1646a6c325.tar.gz |
[darwin] Use weak pointer to mbgl::Layer
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer_Private.h | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm index 05885bc63e..302dafdd75 100644 --- a/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/darwin/src/MGLStyleLayer.mm @@ -14,13 +14,14 @@ const MGLExceptionName MGLInvalidStyleLayerException = @"MGLInvalidStyleLayerExc @implementation MGLStyleLayer { std::unique_ptr<mbgl::style::Layer> _pendingLayer; + mapbox::base::WeakPtr<mbgl::style::Layer> _weakLayer; } - (instancetype)initWithRawLayer:(mbgl::style::Layer *)rawLayer { if (self = [super init]) { _identifier = @(rawLayer->getID().c_str()); - _rawLayer = rawLayer; - _rawLayer->peer = LayerWrapper { self }; + _weakLayer = rawLayer->makeWeakPtr(); + rawLayer->peer = LayerWrapper { self }; } return self; } @@ -32,6 +33,11 @@ const MGLExceptionName MGLInvalidStyleLayerException = @"MGLInvalidStyleLayerExc return self; } +- (mbgl::style::Layer *)rawLayer +{ + return _weakLayer.get(); +} + - (void)addToStyle:(MGLStyle *)style belowLayer:(MGLStyleLayer *)otherLayer { if (_pendingLayer == nullptr) { diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index 314f61f680..5c6d12cc89 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -27,7 +27,8 @@ struct LayerWrapper { if (!self.rawLayer) { \ [NSException raise:MGLInvalidStyleLayerException \ format: \ - @"-[MGLStyle removeLayer:] has been called " \ + @"-Either this layer got invalidated after the style change or " \ + @"[MGLStyle removeLayer:] has been called " \ @"with this instance but another style layer instance was added with the same identifer. It is an " \ @"error to send any message to this layer since it cannot be recovered after removal due to the " \ @"identifier collision. Use unique identifiers for all layer instances including layers of " \ |