Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avalonia MapControl Hangs App if no Internet Connection #2226

Open
robloo opened this issue Oct 19, 2023 · 7 comments
Open

Avalonia MapControl Hangs App if no Internet Connection #2226

robloo opened this issue Oct 19, 2023 · 7 comments

Comments

@robloo
Copy link

robloo commented Oct 19, 2023

Mapsui Version

4.1.0

Mapsui Platform

Avalonia 11.1

Device
Windows 10 Pro

Describe the bug

If no internet connection is available to load map tiles, the MapControl will fail to initialize properly and essentially hangs the application.

To Reproduce

TBD

Expected behavior

This situation should fail gracefully and the MapControl should just be non-functional or not show with a blank map layer. It can retry behind the scenes but should never cause an application hang.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

This is worked-around on the app side for now by pinging for an internet connection before instantiating the MapControl. This is inherently unreliable though and is best handled within Mapsui or Brutile itself.

@pauldendulk
Copy link
Member

I don't see this if I start the Avalonia desktop sample on Windows without internet. If can still use the app, switch samples, and if I open for instance the Atlas sample I can see all the items and can pan and zoom.

Could it be related to some of the layers you use? Can you selectively turn layers off the see if the problem remains?

image

@robloo
Copy link
Author

robloo commented Oct 20, 2023

@pauldendulk Thanks for taking a look at this.

It was a good idea to check the layers. The offending layer is the Bing maps tile layer:

            var tileLayer = new Mapsui.Tiling.Layers.TileLayer(
                BruTile.Predefined.KnownTileSources.Create(
                    BruTile.Predefined.KnownTileSource.BingRoads,
                    ApiKeys.BingMapsKey));
            map.Layers.Add(tileLayer);

When this is commented out the application doesn't hang. I should also add it appears it is caught in a polling loop trying to download tiles. Sometimes it's possible to click away from the control so the application hasn't completely hanged/blocked the UIThread. It is just doing something that takes all resources.

Here is the full init code is below code:

            var map = new Mapsui.Map()
            {
                BackColor = new Mapsui.Styles.Color(0xFF, 0xFF, 0xFF, 0xFF)
            };
            map.Navigator.Limiter = new ViewportLimiterKeepWithinExtent();

            // Add the map tiles layer (actual mapping data)
            var tileLayer = new Mapsui.Tiling.Layers.TileLayer(
                BruTile.Predefined.KnownTileSources.Create(
                    BruTile.Predefined.KnownTileSource.BingRoads,
                    ApiKeys.BingMapsKey));
            map.Layers.Add(tileLayer);

            // Add the pins layer
            this.pins.Clear();
            this.pinsLayer = new WritableLayer
            {
                Name = "Pins Layer",
                Style = new VectorStyle
                {
                    Fill = new Brush(new Mapsui.Styles.Color(0xF4, 0x64, 0x11, 0xFF)),
                    Outline = new Pen(Mapsui.Styles.Color.White, 1)
                }
            };
            map.Layers.Add(this.pinsLayer);

@pauldendulk
Copy link
Member

pauldendulk commented Oct 22, 2023

I can not reproduce the problem so far. There is probably a real issue underneath but I need to reproduce it in order to fix it. Please help me to reproduce it.

It created a minimal sample based on the code you pasted above. Please check it out to see if you can reproduce it. If not, what else could play a role?

https://github.com/pauldendulk/ReproduceMapsuiIssueWithNoInternet

In order to reproduce it I just turn off my wifi. That may not be the circumstance under which this happens. Perhaps it only occurs when the status of internet is still unclear (silently hanging). How does it behave in your app when you just turn off wifi?

@pauldendulk
Copy link
Member

This issue might be related: #1889

@pauldendulk
Copy link
Member

@robloo I created a minimal sample trying to reproduce it but failed. Could you look into the difference with your situation?

@robloo
Copy link
Author

robloo commented Nov 8, 2023

Thanks for taking a deeper look at this. I think I'll try to run using Mapsui code directly in the app being tested. That will let me step through and debug better to see where the problem might be. I'll try to do this within the next week or so.

@pauldendulk
Copy link
Member

pauldendulk commented Nov 8, 2023

Some thoughts:

  • It could be related to caching. In this case you would need quite some data, so longer period of browsing the map.
  • The TileLayer has ab ITileCache. You can provide your own implementation for that.
  • The TileLayer has constructor parameter to set the size of the cache, minTiles and maxTiles, you might want to make it smaller, but not too small.
  • To be able to pass those parameters in you need to use the underlying create method which constructs the TileLayer. Take look in BruTile's BruTile.Predefined.KnownTileSources.Create method.https://github.com/BruTile/BruTile/blob/38403abc53b2fdaaceebf575b3f880f772e3892c/BruTile/Predefined/KnownTileSources.cs#L87
  • It could be related to threading and thread pool starvation.
  • It might be related to pending requests cumulating while waiting for the internet connection to time out (this should not happen, it would be a flaw in the Mapsui design).

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

No branches or pull requests

2 participants