fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.68k stars 847 forks source link

[BUG] Impeller causes crash when zooming into large OverlayImage #1918

Open Finni123 opened 1 week ago

Finni123 commented 1 week ago

What is the bug?

I added a large (about 7000x8000 pixel with 5.6 MB) image from my local assets to a map as a RotatedOverlayImage. On Android, everything works fine, but on iOS, zooming in on the image causes the app to crash with this error:

[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not create color texture.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Render target does not have color attachment at index 0.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not create color texture.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Render target does not have color attachment at index 0.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Render target does not have color attachment at index 0.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Subpass render target is invalid.
* thread #48, stop reason = EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=1450 MB)
    frame #0: 0x00000001dbfc4924 libsystem_pthread.dylib`start_wqthread
libsystem_pthread.dylib`start_wqthread:
->  0x1dbfc4924 <+0>: stp    xzr, xzr, [sp, #-0x10]!
    0x1dbfc4928 <+4>: bl     0x1dbfc4ce4               ; _pthread_wqthread
    0x1dbfc492c <+8>: brk    #0x1
libsystem_pthread.dylib`thread_start:
    0x1dbfc4930 <+0>: stp    xzr, xzr, [sp, #-0x10]!
Target 0: (Runner) stopped.

How can we reproduce it?

    FlutterMap(
      mapController: MapController(),
      children: [
        OverlayImageLayer(
          overlayImages: [
            RotatedOverlayImage(
              bottomLeftCorner: // some LatLng,
              bottomRightCorner: // some LatLng,
              topLeftCorner: // some LatLng,
              imageProvider: AssetImage( /* path to a very big asset image */ ),
            ),
          ],
        ),
      ],
    );

Do you have a potential solution?

This comment gave me the idea to try to disable Impeller as described here: Use flutter run --enable-impeller or add <key>FLTEnableImpeller</key><false/> to Info.plist.

This indeed fixes it, the map does not crash anymore, and it runs with better performance too.

I thought it would be good to post this here, so that other people who run into this issue can find the solution.

Platforms

Android 14, Windows 10, Flutter 3.22.1

Severity

Fatal: Causes the application to crash

Finni123 commented 1 week ago

Unfortunately I realized that the app still crashes when I view the map, then I navigate to another page and then I navigate back to the map again. It seems like the big overlay image is loaded into memory once more instead of being reused, which causes the memory limit to be exceeded. How can I fix this?

JaffaKetchup commented 1 week ago

Unfortunately I realized that the app still crashes when I view the map, then I navigate to another page and then I navigate back to the map again. It seems like the big overlay image is loaded into memory once more instead of being reused, which causes the memory limit to be exceeded. How can I fix this?

On what platforms does this occur, and does it occur with and without Impeller?

Also, please report this issue to Flutter with an example using flutter_map (they're used to it by now :D) if you have time. If not, please provide the image here if you can and I'll file the report.

Finni123 commented 1 week ago

You can find the image I used here. I built for iOS on a real iPhone 7, with and without Impeller. Disabling Impeller made it somewhat better and the app crashes later, but it still crashes. Unfortunately I don't have a lot of time currently, so if you can replicate the crash, I would be grateful if you could file the report.