greensopinion / flutter-vector-map-tiles

A plugin for `flutter_map` that enables the use of vector tiles.
BSD 3-Clause "New" or "Revised" License
137 stars 69 forks source link

Raster mode tile cancellation #205

Open stefcon opened 6 months ago

stefcon commented 6 months ago

Whenever I do fast zoom in/out, I'm getting following error:

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following CancellationException was thrown:
Cancelled

When the exception was thrown, this was the stack:
#0      TileLoader._renderTile (package:vector_map_tiles/src/raster/tile_loader.dart:72:7)
#1      TileLoader._renderJob (package:vector_map_tiles/src/raster/tile_loader.dart:66:40)
#2      ImmediateExecutor.submit (package:executor_lib/src/immdediate_executor.dart:17:44)
#3      ConcurrencyExecutor._startJob (package:executor_lib/src/concurrency_executor.dart:71:10)
#4      ConcurrencyExecutor._startJobs (package:executor_lib/src/concurrency_executor.dart:57:7)
#5      ConcurrencyExecutor.submit (package:executor_lib/src/concurrency_executor.dart:39:5)
#6      TileLoader.loadTile (package:vector_map_tiles/src/raster/tile_loader.dart:61:22)
<asynchronous suspension>
#7      _FutureImageProvider._load.<anonymous closure> (package:vector_map_tiles/src/raster/future_tile_provider.dart:64:47)
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════════════════════════

I saw that in latest release note for 7.3.1 it is noted that it has something to do with that:

The problem is that visibly slows down the map when it happens, and in addition it also overflows my crashlytics service. Is there some way that this is supposed to be handled outside the library and is it something that is being worked on currently? Also, If someone would like to explain why this feature is now being handled this way and what it enables generally would be great.

PatrickWulfe commented 6 months ago

I'm also having issues with the package overflowing my crashlytics service.

greensopinion commented 3 weeks ago

Likely there's somewhere in the code that we're not handling exceptions across an async boundary, causing exceptions to go to the default exception handler. https://dart.dev/libraries/async/futures-error-handling#potential-problem-failing-to-register-error-handlers-early

A couple of options come to mind:

mart-fractic commented 1 week ago

Thank you very much for the response, that workaround seems reasonable for now. The following works for me to suppress the errors (and in my case, let integration tests now pass with a zero exit code). Very nice to finally be rid of the errors.

// flutter pub add executor_lib
import "package:executor_lib/executor_lib.dart";

void main() async {
  FlutterError.onError = (details) {
    // Flutter map currently has a bug with async vector tile loading. On
    // cancellation (i.e. when a request for a tile has been sent but its result
    // is no longer necessary), a CancellationException is throw and not
    // properly handled. Silently ignore this exception type.
    if (details.exception is CancellationException) {
      return;
    }
    FlutterError.presentError(details);
  };
  return runApp(...);
}