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

[core] Localize and simplify state for MapChangeDidFinishLoadingMap event - #4524

Merged
jfirebaugh merged 1 commit into
release-ios-3.2.0-android-4.0.0from
4500
Mar 30, 2016
Merged

jfirebaugh merged 1 commit into
release-ios-3.2.0-android-4.0.0from
4500

Conversation

@jfirebaugh

Copy link
Copy Markdown
Contributor

Fixes #4500 for iOS.

Only Map needs to track the loaded state, and it can simply be set when beginning to load a style and reset when finished.

The only commit related to MapData::loading that I could find was 2ee7b02. I thought I remembered some additional adjustments to how this variable was used based on past bugs, but could not find any. There is one branch that references it, tmpsantos-MapChangeDidFinishLoadingMap, which looks to be obsolete. @tmpsantos do you remember what this was about? Is anyone else aware of subtleties relating to MapData::loading or MapChangeDidFinishLoadingMap that I forgot to take into account?

This provides an alternative fix for #4512 on Android, but the least risky approach would be to continue using that workaround for the release and perhaps revert it on the main branch.

I attempted to write a test for MapChangeDidFinishLoadingMap, but it is very difficult. It will be easier once #2909 lands.

👀 @1ec5 @brunoabinader @tmpsantos

@jfirebaugh jfirebaugh self-assigned this Mar 29, 2016
@jfirebaugh jfirebaugh added this to the ios-v3.2.0 milestone Mar 29, 2016
@jfirebaugh

Copy link
Copy Markdown
Contributor Author

I should have included my reasoning for why this is thread safe. The relevant events are:

Main thread Map thread
map.setStyleURL/setStyleJSON
invocation of context.setStyleURL / setStyleJSON
map.renderSync sync invocation of context.renderSync

Invocations, including synchronous ones, are FIFO, so the fullyLoaded result of the sync invocation of context.renderSync is guaranteed to reflect the loaded status of the most recently set style. The following execution schedule is not possible, for example:

Main thread Map thread
map.setStyleURL(A)
map.setStyleURL(B)
invocation of context.setStyleURL(A)
map.renderSync sync invocation of context.renderSync
MapChangeDidFinishLoadingMap emitted for A, loading is reset to false
invocation of context.setStyleURL(B)
map.renderSync
MapChangeDidFinishLoadingMap should be emitted for B, but isn't

@tmpsantos

Copy link
Copy Markdown
Contributor

@tmpsantos do you remember what this was about?

That branch is obsolete. Just deleted it.

Is anyone else aware of subtleties relating to MapData::loading or MapChangeDidFinishLoadingMap that I forgot to take into account?

We have several methods that are currently crashing because setStyleURL is async. For instance addLayer, addClass, isLoaded and several others. We should have a signal (MapChangeDidFinishLoadingStyle?) emitted right after loadStyleJSON.

On Android for instance MapChangeDidFinishLoadingMap is used to indicate that the style was loaded as a whole but we need something to indicate that the style JSON arrived (and the style object was created). Otherwise we might ended up rendering a partial state and later add a custom layer or class.

@tmpsantos

Copy link
Copy Markdown
Contributor

I started implementing this new signal and realized that it would be better implemented after we get rid of the context thread because we can safely call view.notifyMapChange from MapContext:::loadStyleJSON after that.

@tmpsantos

Copy link
Copy Markdown
Contributor

👍 for this one, created #4527 for my other comments. Sorry for the noise.

@1ec5

1ec5 commented Mar 30, 2016

Copy link
Copy Markdown
Contributor

👍

…vent

Only Map needs to track this state, and it can simply be set when beginning to load a style and reset when finished.
@brunoabinader

Copy link
Copy Markdown
Contributor

Excellent! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants