summaryrefslogtreecommitdiff
path: root/platform/darwin/src
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-02-26 08:10:31 -0500
committerJulian Rex <julian.rex@mapbox.com>2018-02-26 08:10:31 -0500
commitb07fda134777b3b82f64c4b39902158b11b47ae7 (patch)
treee1c147da3994d369b3222dd88c3a67a7c6a1038a /platform/darwin/src
parent48918fae8ba3f2ed216a68a5d41d4dedafbddc09 (diff)
downloadqtlocation-mapboxgl-b07fda134777b3b82f64c4b39902158b11b47ae7.tar.gz
[ios] Potential fix for over retain/release issues with adding layers to styles. Integration tests run on device.
Diffstat (limited to 'platform/darwin/src')
-rw-r--r--platform/darwin/src/MGLOpenGLStyleLayer.mm12
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm8
2 files changed, 17 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm
index 8933a77382..9f957b7082 100644
--- a/platform/darwin/src/MGLOpenGLStyleLayer.mm
+++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm
@@ -15,7 +15,11 @@
when creating an OpenGL style layer.
*/
void MGLPrepareCustomStyleLayer(void *context) {
- MGLOpenGLStyleLayer *layer = (__bridge MGLOpenGLStyleLayer *)context;
+
+ // Pair retain/release during rendering (see MGLFinishCustomStyleLayer)
+ id retaineee = (__bridge id)context;
+ MGLOpenGLStyleLayer *layer = (__bridge MGLOpenGLStyleLayer*)CFBridgingRetain(retaineee);
+
[layer didMoveToMapView:layer.style.mapView];
}
@@ -47,7 +51,8 @@ void MGLDrawCustomStyleLayer(void *context, const mbgl::style::CustomLayerRender
when creating an OpenGL style layer.
*/
void MGLFinishCustomStyleLayer(void *context) {
- MGLOpenGLStyleLayer *layer = (__bridge_transfer MGLOpenGLStyleLayer *)context;
+ // Release the layer (since we retained it in the initialization)
+ MGLOpenGLStyleLayer *layer = CFBridgingRelease(context);
[layer willMoveFromMapView:layer.style.mapView];
}
@@ -97,11 +102,12 @@ void MGLFinishCustomStyleLayer(void *context) {
@return An initialized OpenGL style layer.
*/
- (instancetype)initWithIdentifier:(NSString *)identifier {
+ // Note, do not retain self here, otherwise MGLOpenGLStyleLayer will never be dealloc'd
auto layer = std::make_unique<mbgl::style::CustomLayer>(identifier.UTF8String,
MGLPrepareCustomStyleLayer,
MGLDrawCustomStyleLayer,
MGLFinishCustomStyleLayer,
- (__bridge_retained void *)self);
+ (__bridge void*)self);
return self = [super initWithPendingLayer:std::move(layer)];
}
diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm
index 6400b8fcbf..2a70cab563 100644
--- a/platform/darwin/src/MGLStyleLayer.mm
+++ b/platform/darwin/src/MGLStyleLayer.mm
@@ -38,6 +38,10 @@
"to the style more than once is invalid.", self, style];
}
+ // Since we're adding self to a C++ collection, we need to retain ourselves, so that we don't
+ // end up with a dangling pointer
+ CFBridgingRetain(self);
+
if (otherLayer) {
const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
style.rawStyle->addLayer(std::move(_pendingLayer), belowLayerId);
@@ -51,6 +55,10 @@
if (self.rawLayer == style.rawStyle->getLayer(self.identifier.UTF8String)) {
_pendingLayer = style.rawStyle->removeLayer(self.identifier.UTF8String);
}
+
+ // Pair the retain above, and release self, since we're now removed from the collection
+ CFTypeRef toRelease = (__bridge CFTypeRef)self;
+ CFBridgingRelease(toRelease);
}
- (void)setVisible:(BOOL)visible