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

onMapReady not getting called when offline when a (largish) offline region is present #4500

Closed

Description

@tnightingale

Following up on #4486: Turns out the issue that I encountered only seems to occur when a offline region larger than a particular size has been downloaded. In my test case this occurs with a region of 87.353 megabytes but not with a region of 74.243 megabytes.

Testing steps are mostly the same as I outlined in #4486. The difference being that a OfflineRegion of ~87MB (or probably larger) is downloaded the first time application is loaded with the WiFi enabled.

@zugaldia, @jfirebaugh does that make sense?

I am putting together a test Activity in the TestApp to demonstrate.

Activity

  1. zugaldia commented on Mar 28, 2016

    @zugaldia
    Member

    @tnightingale Interesting, thanks again for the feedback. Have you noticed by any chance any differences between the first and the second (and further) downloaded regions? In other words, does this behavior happen to all regions downloaded by the app?

    Either way, some code / region definitions would be really helpful.

  2. tnightingale commented on Mar 29, 2016

    @tnightingale
    Author

    I have committed my example code here: tnightingale@4d6a3db.

    There is a new Activity called "OnMapLoadBug Map" (for want of a better name). It's a clone of the OfflineActivity but provides two hard-coded OfflineRegionDefinitions instead of providing a method of creating a new one based on the map's viewport.

    If you perform the testing steps I defined in #4486 but when loading the map on WiFi instead of just letting the map filling the ambient cache try download the small or large offline region.

    I find that if I download the small offline region then restart process with WiFi disabled onMapReady gets called. If I do the same with the large offline region onMapReady never gets called.

    The large region is a segment of downtown Wellington, NZ while the small region is just a suburb of the city. I haven't tried with other regions yet.

  3. added this to the android-v4.0.0 milestone on Mar 29, 2016
  4. added
    Android
    on Mar 29, 2016
  5. tnightingale commented on Mar 29, 2016

    @tnightingale
    Author

    As I test this more I am getting inconsistent results:

    I open the application with WiFi disabled, load the map and onMapLoad() will get called as expected. I then kill the application and repeat multiple times in a row and it continues to work. Then seemingly randomly it just stops.

    I cannot pinpoint a specific sequence of events or actions that causes it to occur... Though it does seem that the presence of downloaded offline regions increases the chances of it happening.

    Once onMapLoad() stops firing it won't fire again if the device is offline even after killing the application and reopening it. (If WiFi is re-enabled onMapLoad is called consistently but as soon as it is disabled again it will stop). The only way to resolve it seems to be to clear the application's data or uninstall & reinstall the application.

    I'm stumped :-\

  6. tobrun commented on Mar 29, 2016

    @tobrun
    Member

    @tnightingale thank you for contributing the code, I'm trying to reproduce locally.

  7. tobrun commented on Mar 29, 2016

    @tobrun
    Member

    I was able to identify the following possible scenario's:

    No internet

    Having no internet from start results in a black screen without a map ready callback. (works as designed)

    device-2016-03-29-112329

    Internet enabled - home - internet disabled - reopen

    I had internet enabled at start, opening the Map results in a map ready callback.

    device-2016-03-29-112629

    After click home, disable wifi and return to the app. I'm seeing an not reloaded map without a callback. Becuase the MapView wasn't recreated, the map was already ready.

    device-2016-03-29-113058

    Internet enabled - back - internet disabled - reopen

    I had internet enabled at start, opening the Map results in a map ready callback.
    device-2016-03-29-112629

    After I click back, click home, disable wifi, return to the app and reopen OnMapLoadBug. I'm seeing the map reloading with content and seeing the callback occurring.

    device-2016-03-29-113509

    Initial loaded, kill app and reopen

    This test will focus on @tnightingale description of once in offline downloaded and afterwards keep killing app / reopening it until it stops providing a callback.

    In the first tries, I'm able to produce the normal behaviour as shown above but after 4 tries, the callback is not invoked anymore and the camera will not move to the correct position:

    device-2016-03-29-114024

    What is happening when we are not receiving the callback:

    Mapchange 0 -> REGION_WILL_CHANGE
    Mapchange 3 -> REGION_DID_CHANGE
    Mapchange 5 -> WILL_START_LOADING_MAP
    Mapchange 0 -> REGION_WILL_CHANGE
    Mapchange 3 -> REGION_DID_CHANGE
    Mapchange 11 -> WILL_START_RENDERING_MAP
    Mapchange 8 -> WILL_START_RENDERING_FRAME
    Mapchange 9 -> DID_FINISH_RENDERING_FRAME
    Mapchange 8 -> WILL_START_RENDERING_FRAME
    Mapchange 10 -> DID_FINISH_RENDERING_FRAME_FULLY_RENDERED
    Mapchange 13 -> DID_FINISH_RENDERING_MAP_FULLY_RENDERED
    Mapchange 8 -> WILL_START_RENDERING_FRAME
    Mapchange 9 -> DID_FINISH_RENDERING_FRAME
    Mapchange 8 -> WILL_START_RENDERING_FRAME
    Mapchange 10 -> DID_FINISH_RENDERING_FRAME_FULLY_RENDERED
    Mapchange 13 -> DID_FINISH_RENDERING_MAP_FULLY_RENDERED
    Mapchange 8 -> WILL_START_RENDERING_FRAME
    Mapchange 10 -> DID_FINISH_RENDERING_FRAME_FULLY_RENDERED
    

    It seems we are waiting for a Mapchange 6 to occur before passing control back to the user. I currently think we can replace that with Mapchange 13 instead (aka DID_FINISH_RENDERING_MAP_FULLY_RENDERED).

  8. tobrun commented on Mar 29, 2016

    @tobrun
    Member

    @jfirebaugh

    On Android we were waiting for DID_FINISH_LOADING_MAP callback from core, it seems this is not called with being offline while having offline enabled. Replacing this event with DID_FINISH_RENDERING_MAP_FULLY_RENDERED resolved it for the offline case shown above. I'm going to do some testing to see if this has unwanted side effects. At this point I'm not seeing any.

    FWIW the related code from core map.cpp:

        if (!fullyLoaded) {
            renderState = RenderState::partial;
        } else if (renderState != RenderState::fully) {
            renderState = RenderState::fully;
            view.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered);
            if (data->loading) {
                data->loading = false;
                view.notifyMapChange(MapChangeDidFinishLoadingMap);
            }
        }

    We are now waiting for the former notifyMapChange to occur instead of the latter.

  9. added a commit that references this issue on Mar 29, 2016
  10. self-assigned this
    on Mar 29, 2016
  11. jfirebaugh commented on Mar 29, 2016

    @jfirebaugh
    Contributor

    I'm not able to replicate this behavior myself. I'm using the TestApp, simulator, an offline region, some added logging in mbgl core map.cpp and MapView.java, and turning off wifi, and everything works as expected.

    @tobrun Can you post the code and the steps you took to reproduce this? Is it only reproducible with an actual device?

  12. tobrun commented on Mar 29, 2016

    @tobrun
    Member

    @jfirebaugh

    Steps

    I was able to reproduce it locally with:

    • Running with internet just once, turn off WiFi
    • Kill app (open task launcher, swipe app out)
    • Open app, go to related activity
      • if not reproducible go back to step 2

    I had to go through 4 iterations before being able to reproduce.

    Code

    I used the branch from @tnightingale.

    Thanks again @tnightingale, having code makes it so much easier.

  13. added a commit that references this issue on Mar 29, 2016
  14. removed this from the android-v4.0.0 milestone on Mar 29, 2016
  15. jfirebaugh commented on Mar 29, 2016

    @jfirebaugh
    Contributor

    Ok, I'll keep digging to see if I can figure out the underlying issue, and we'll go with #4512 as the solution for 4.0.0.

  16. jfirebaugh commented on Mar 29, 2016

    @jfirebaugh
    Contributor

    Nope, still can't replicate it.

    1. Clean build at tnightingale@4d6a3db
    2. With Wifi on, launch TestApp in simulator
    3. Go to "OnMapLoadBug Map"
    4. Start "Large region" download, wait for completion
    5. Turn Wifi off
    6. Open task launcher, swipe app out
    7. Relaunch, go to "OnMapLoadBug Map"
    8. App and logs indicate onMapReady is called
    9. Repeat starting at step 6

    I tried steps 6-9 more than a dozen times and in no instance did onMapReady fail to be called.

  17. jfirebaugh commented on Mar 29, 2016

    @jfirebaugh
    Contributor

    I was able to replicate the issue after enabling airplane mode in the simulator. This was the key: it does not replicate when turning wifi off in the simulator's host OS.

    The issue is a race condition in the state management of MapData::loading. When loaded in airplane mode and the style in the offline database:

    1. The offline database satisfies the initial request for the style. MapContext::loadStyleJSON is triggered, sets data.loading = true, and triggers an async update.
    2. The revalidation attempt for the style fails due to lack of network access. The request callback runs this code which resets data.loading to false.
    3. The async update runs, triggers a render, and this code. The map is fully loaded, and MapChangeDidFinishLoadingMap should be emitted, but since data.loading is now false, it isn't.

    This is a great illustration of why state is a liability. Always endeavor to minimize or eliminate state. I'm going to go back and review why MapData::loading exists and whether we can eliminate it.

  18. tnightingale commented on Mar 29, 2016

    @tnightingale
    Author

    A race condition would certainly be consistent with my experiences. My other test application seemed to experience the issue more frequently. Which was probably due was due to the fact it's main Activity loaded two maps on screen and called listOfflineRegions() on init.

    Great work, thanks for persevering!

  19. bleege commented on Mar 29, 2016

    @bleege
    Contributor

    Wow! Where you able to replicate this using Airplane Mode on actual device too or just the emulator? I wonder if on the emulator it was still considering it's Network connection (via the host computer) to be different from it's WiFi connection and therefore still able to load data from the network? Android Emulator are horrible.

    This is a great illustration of why state is a liability. Always endeavor to minimize or eliminate state.

    Truth. Immutability FTW!

  20. added
    iOS
    on Mar 29, 2016
  21. added this to the ios-v3.2.0 milestone on Mar 29, 2016
  22. jfirebaugh commented on Mar 29, 2016

    @jfirebaugh
    Contributor

    This will affect iOS, because it also uses MapChangeDidFinishLoadingMap. Tagging for 3.2.0.

  23. jfirebaugh commented on Mar 30, 2016

    @jfirebaugh
    Contributor

    Fixed for iOS with #4524.

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

Metadata

Metadata

Assignees

Labels

AndroidiOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions