-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix CustomLayer context retain count #10765
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ void MGLDrawCustomStyleLayer(void *context, const mbgl::style::CustomLayerRender | |
when creating an OpenGL style layer. | ||
*/ | ||
void MGLFinishCustomStyleLayer(void *context) { | ||
MGLOpenGLStyleLayer *layer = (__bridge MGLOpenGLStyleLayer *)context; | ||
MGLOpenGLStyleLayer *layer = (__bridge_transfer MGLOpenGLStyleLayer *)context; | ||
[layer willMoveFromMapView:layer.style.mapView]; | ||
} | ||
|
||
|
@@ -101,7 +101,7 @@ - (instancetype)initWithIdentifier:(NSString *)identifier { | |
MGLPrepareCustomStyleLayer, | ||
MGLDrawCustomStyleLayer, | ||
MGLFinishCustomStyleLayer, | ||
(__bridge void *)self); | ||
(__bridge_retained void *)self); | ||
return self = [super initWithPendingLayer:std::move(layer)]; | ||
} | ||
|
||
|
@@ -116,9 +116,7 @@ - (void)setStyle:(MGLStyle *)style { | |
[NSException raise:@"MGLLayerReuseException" | ||
format:@"%@ cannot be added to more than one MGLStyle at a time.", self]; | ||
} | ||
_style.openGLLayers[self.identifier] = nil; | ||
_style = style; | ||
_style.openGLLayers[self.identifier] = self; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place where this dictionary was being used @1ec5 ; transferring the ownership is a better solution (and fixes the crash) |
||
} | ||
|
||
- (void)addToStyle:(MGLStyle *)style belowLayer:(MGLStyleLayer *)otherLayer { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,6 @@ @interface MGLStyle() | |
@property (nonatomic, readonly, weak) MGLMapView *mapView; | ||
@property (nonatomic, readonly) mbgl::style::Style *rawStyle; | ||
@property (readonly, copy, nullable) NSURL *URL; | ||
@property (nonatomic, readwrite, strong) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLOpenGLStyleLayer *) *openGLLayers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this dictionary wound up unused after #8626. The original purpose of this dictionary was to allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @1ec5 verified There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @1ec5 |
||
@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSObject *, MGLTextLanguage *) *) *localizedLayersByIdentifier; | ||
|
||
@end | ||
|
@@ -169,7 +168,6 @@ - (instancetype)initWithRawStyle:(mbgl::style::Style *)rawStyle mapView:(MGLMapV | |
if (self = [super init]) { | ||
_mapView = mapView; | ||
_rawStyle = rawStyle; | ||
_openGLLayers = [NSMutableDictionary dictionary]; | ||
_localizedLayersByIdentifier = [NSMutableDictionary dictionary]; | ||
} | ||
return self; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a corner case, but: this will leak a
MGLOpenGLStyleLayer
that'sinit
'd but never added to a map.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😞 I knew I was missing something! Moved to : #10771