You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
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
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.
@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.
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.
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 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)
Internet enabled - home - internet disabled - reopen
I had internet enabled at start, opening the Map results in a map ready callback.
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.
Internet enabled - back - internet disabled - reopen
I had internet enabled at start, opening the Map results in a map ready callback.
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.
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:
What is happening when we are not receiving the callback:
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).
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.
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?
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:
The offline database satisfies the initial request for the style. MapContext::loadStyleJSON is triggered, sets data.loading = true, and triggers an async update.
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.
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.
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.
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.
Activity
zugaldia commentedon Mar 28, 2016
@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.
tnightingale commentedon Mar 29, 2016
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.
Added activity demonstrating onMapLoad bug outlined in mapbox#4500.
tnightingale commentedon Mar 29, 2016
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-enabledonMapLoadis 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 :-\
tobrun commentedon Mar 29, 2016
@tnightingale thank you for contributing the code, I'm trying to reproduce locally.
tobrun commentedon Mar 29, 2016
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)
Internet enabled - home - internet disabled - reopen
I had internet enabled at start, opening the Map results in a map ready callback.
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.
Internet enabled - back - internet disabled - reopen
I had internet enabled at start, opening the Map results in a map ready callback.

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.
Initial loaded, kill app and reopen
This test will focus on @tnightingale description of
once in offline downloaded and afterwards keep killing app / reopening ituntil 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:
What is happening when we are not receiving the callback:
It seems we are waiting for a
Mapchange 6to occur before passing control back to the user. I currently think we can replace that withMapchange 13instead (aka DID_FINISH_RENDERING_MAP_FULLY_RENDERED).tobrun commentedon Mar 29, 2016
@jfirebaugh
On Android we were waiting for
DID_FINISH_LOADING_MAPcallback from core, it seems this is not called with being offline while having offline enabled. Replacing this event withDID_FINISH_RENDERING_MAP_FULLY_RENDEREDresolved 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:We are now waiting for the former
notifyMapChangeto occur instead of the latter.[android] #4500 - OnMapReady not invoked for offline maps
jfirebaugh commentedon Mar 29, 2016
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.cppandMapView.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?
tobrun commentedon Mar 29, 2016
@jfirebaugh
Steps
I was able to reproduce it locally with:
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.
[android] #4500 - OnMapReady not invoked for offline maps
jfirebaugh commentedon Mar 29, 2016
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.
jfirebaugh commentedon Mar 29, 2016
Nope, still can't replicate it.
I tried steps 6-9 more than a dozen times and in no instance did onMapReady fail to be called.
jfirebaugh commentedon Mar 29, 2016
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:MapContext::loadStyleJSONis triggered, setsdata.loading = true, and triggers an async update.MapChangeDidFinishLoadingMapshould be emitted, but sincedata.loadingis 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::loadingexists and whether we can eliminate it.tnightingale commentedon Mar 29, 2016
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!
bleege commentedon Mar 29, 2016
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.
Truth. Immutability FTW!
jfirebaugh commentedon Mar 29, 2016
This will affect iOS, because it also uses
MapChangeDidFinishLoadingMap. Tagging for 3.2.0.jfirebaugh commentedon Mar 30, 2016
Fixed for iOS with #4524.