-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Warn when accessing MGLStyle before style is loaded #7639
Conversation
@boundsj, thanks for your PR! By analyzing this pull request, we identified @1ec5, @incanus and @friedbunny to be potential reviewers. |
|
@1ec5 the macOS |
Removing the call to
|
if (_isWaitingForStyleLoad) { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
NSLog(@"WARNING: -[MGLMapView style] was called before -[MGLMapViewDelegate mapView:didFinishLoadingStyle:]. Wait for the map to finish loading the style before attempting to change the style at runtime."); |
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.
Mention in the message that the warning will only appear once.
@@ -390,6 +393,8 @@ - (void)commonInit | |||
{ | |||
MGLinitializeRunLoop(); | |||
|
|||
_isWaitingForStyleLoad = YES; |
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.
Setting or reloading the style URL should also cause us to wait for the style to load. If you want to be sure the flag gets set at the right times, replace any occurrences of _style
with self.style
, then override -setStyle:
to set this flag.
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.
Fixed in 80f96a1
@@ -2275,6 +2281,17 @@ - (void)updateAnnotationCallouts { | |||
return _mbglMap; | |||
} | |||
|
|||
- (MGLStyle *)style | |||
{ | |||
if (_isWaitingForStyleLoad) { |
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.
Add && _style
to silence the initial warning triggered by the attribution view. The style isn’t set by the time -commonInit
calls -installAttributionView
.
As an alternative to adding a private flag to MGLMapView, we could add a |
I tested that and hit this:
I'm not sure about a way around this offhand. Since this works for the iOS SDK, can we either land this PR as is and file a bug for macOS specifically about the warning getting triggered -or- can I remove the macOS implementation and create a follow up ticket to implement it? |
I suggested a fix in #7639 (comment) – I think this would be a good fix to have on both platforms. I don’t think we should be removing any calls to |
@1ec5 I'm sorry, I somehow missed #7639 (comment) before. What I was trying to say in #7639 (comment) is that, when I remove the call to I'll add |
I see, that’s an interesting edge case that’ll affect any macOS code that binds to the As far as solutions to this problem, what if we avoid initializing and setting |
Going to make this a separate PR. Making |
A workaround for the KVO-triggered warning is difficult to come by, even if we make the I have a change ready that makes the |
These changes are in #7664. |
No description provided.