Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Setting styleURL immediately after initialization sometimes fails #1767

Merged
merged 1 commit into from
Jul 1, 2015

Conversation

tmpsantos
Copy link
Contributor

Sometimes when I start my app (iOS) with Mapbox in it, it won't load the styles into the map. It generates the default MapKit styled map, without any markers. It's kind of annoying, because the problem is somewhat occurring on a random base.

I load my custom stylesheet as a JSON file and link it to the map via the style url:

mapView?.styleURL = NSURL(string: "asset://\(jsonFile)")

Is it a known issue?

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Jun 22, 2015
@1ec5
Copy link
Contributor

1ec5 commented Jun 22, 2015

Possibly related: #1208, #1279, although those issues reproduce consistently.

Where do you set styleURL? Right after initializing the MGLMapView in -viewDidLoad, or somewhere else? Does the issue reproduce if you initialize the map view with -initWithFrame:styleURL:?

@leandersikma
Copy link
Author

It looks like #1208 is about a wrong file path to the local style URL. My styleURL is actually working and loading, but once in 20 times (or another random number) that you open the app. The style got not applied to map.

View with layout:
screen shot 2015-06-22 at 20 17 33

View with the default layout (hops in sometimes)
screen shot 2015-06-22 at 20 19 59

I'm trying -initWithFrame:styleURL: now. I have to say that the last 20 times I built/started my app, the problem didn't occur. So maybe this one is a little bit more 'stable'.

@picciano
Copy link

I've been meaning to log this. We are seeing this quite often as well.
It happens about 80% of the time with a new build though iTunesConnect/TestFlight. User must force quit, restart app, then markers appear. But I see this running directly from Xcode as well.

This is definitely a real issue. And is annoying as mentioned above.

@1ec5
Copy link
Contributor

1ec5 commented Jun 22, 2015

@picciano, if you’re also initializing and setting the style in separate steps, rather than using -initWithFrame:styleURL:, there may be a race condition because initialization asynchronously fetches the style and tiles. #1488 is probably playing a part in this as well: setting the styleURL separately in -viewDidLoad means you’re switching styles, which causes annotations to “disappear” before they ever get a chance to appear.

@1ec5 1ec5 added the bug label Jun 22, 2015
@1ec5 1ec5 changed the title Mapview doesn't always load styleURL Setting styleURL immediately after initialization sometimes fails Jun 22, 2015
@picciano
Copy link

I'll try that and report back in a couple days. So far, so good.

@picciano
Copy link

Using using -initWithFrame:styleURL: seems to be a good work around for setting the style. I have not seen anymore missing markers by doing this.

@1ec5
Copy link
Contributor

1ec5 commented Jun 23, 2015

Glad to hear it works. Unfortunately, both -initWithFrame:style: and -initWithCoder: (for storyboards) rely on setting styleURL immediately after calling -commonInit. So if there’s a race condition, this only makes it less likely to present itself.

@1ec5
Copy link
Contributor

1ec5 commented Jun 23, 2015

Actually, -initWithFrame:styleURL: should be fine, because styleURL is only ever set once. But -initWithCoder: (again, important for storyboards) does suffer from the same problem as -initWithFrame:, because styleURL ultimately gets set more than once.

@kkaefer
Copy link
Contributor

kkaefer commented Jun 30, 2015

Is this possibly fixed by #1802?

@jfirebaugh
Copy link
Contributor

@tmpsantos Can you investigate and determine if this is fixed?

@tmpsantos
Copy link
Contributor

@tmpsantos Can you investigate and determine if this is fixed?

Sure!

@tmpsantos
Copy link
Contributor

@jfirebaugh it is not fixed, good news is that I managed to reproduce on the linux app:

map.setStyleURL(style1);
map.setStyleURL(style2);
map.setStyleURL(style3);

view->run();

Sometimes I see style1 instead of style3. I'm working on a fix.

@tmpsantos tmpsantos added in progress and removed iOS Mapbox Maps SDK for iOS labels Jul 1, 2015
@tmpsantos
Copy link
Contributor

I have a fix already.

@tmpsantos tmpsantos force-pushed the 1767-setStyleURL_after_initialization branch from a9edd02 to 70b0466 Compare July 1, 2015 07:43
Calling setStyleURL() multiple times in a short period
of time will enqueue requests on the FileSource. The
order they get replied is not guaranteed to be the same
as the order we make the requests. The side effect was
the last style set not always being the one rendered.

Now we cancel the current request if we make a new one
(and there was no point on keeping it around anyway).
@tmpsantos tmpsantos force-pushed the 1767-setStyleURL_after_initialization branch from 5dd9ea5 to 295ea08 Compare July 1, 2015 12:18
@tmpsantos tmpsantos merged commit 295ea08 into master Jul 1, 2015
@mourner mourner removed the ready label Jul 1, 2015
@tmpsantos tmpsantos deleted the 1767-setStyleURL_after_initialization branch July 1, 2015 12:35
@jfirebaugh
Copy link
Contributor

Ah, a request/response race condition -- this is a common error in client-side JS, funny to see it in C++ code. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants