JaffaKetchup / flutter_map_tile_caching

Plugin for flutter_map providing advanced & performant caching and bulk downloading functionality, with many options for region shapes and extra tools
https://pub.dev/packages/flutter_map_tile_caching
GNU General Public License v3.0
117 stars 73 forks source link

[BUG] Animating the movement on large areas throws exceptions #115

Closed tratteo closed 1 year ago

tratteo commented 1 year ago

What is the bug?

Animating the movement in the map on large areas

Using a cached tileProvider with behaviour cacheFirst and moving on the map (I am doing around 100 Km in 1 second) causes tons of this errors to be thrown:

image

FMTCcrash2

In this case I am offline and I try to move out of the cached zone

In this case I am offline and I am using the cached tile provider. Instead of being catched and logged, the error is thrown, causing tons of more exceptions per tile. I think this is related to the issue above.

image

What is the expected behaviour?

Silently fail or at least prevent exceptions to be actually thrown. The error indeed does not happen when not using the cached tile provider.

How can we reproduce this issue?

Do you have a potential solution?

The second error is thrown because of the first one, this is my guess. Indeed in case the first error is not thrown, the FMTCBrowingError is thrown silently (correctly)

Can you provide any other information?

No response

Platforms Affected

Android

Severity

Minimum: Allows normal functioning

Frequency

Often: Occurs more often than when it doesn't

Requirements

JaffaKetchup commented 1 year ago

Hi @tratteo,

In regards to the second issue, there is nothing I can do to prevent it. There are no image bytes to return from the ImageProvider - so the only possible exit is through throwing an exception. Every ImageProvider will do this in the event that it can't retrieve an image. Sometimes Flutter decides to report this silently, and sometimes it doesn't: but I always throw this in the same circumstances every time. You can check the code here: https://github.com/JaffaKetchup/flutter_map_tile_caching/blob/3d723ed052f0e27de50e2f3db351ad95e43c5516/lib/src/providers/image_provider.dart#L157-L173

In regards to the first issue, that code isn't part of my library, and looks to be part of Flutter's ImageCache. It actually looks as though this could be a bug in Flutter - it might be worthwhile opening an issue there and linking here.

Whilst they are likely related, Flutter shouldn't be throwing this kind of error. It likely occurs because Flutter thinks there is a cached image at that key, but in reality, there isn't.

Can you try the following solution when you get a moment? Fork this project and depend on it with an override, then replace the following lines:

https://github.com/JaffaKetchup/flutter_map_tile_caching/blob/3d723ed052f0e27de50e2f3db351ad95e43c5516/lib/src/providers/image_provider.dart#L97-L102

with these:

final error = FMTCBrowsingError(throwError, throwErrorType!);
await evict();
// ImageCache().evict(key); // Uncomment this one if the issue isn't solved without it

provider.settings.errorHandler?.call(error);
throw error;
JaffaKetchup commented 1 year ago

flutter_map v4 may support disabling of loading and pruning of new tiles on demand, for example during animations. See the bottom of https://github.com/fleaflet/flutter_map/pull/1475#issue-1645808772 for more info.