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

[BUG] updateMyLocationEnabled() call on style load causes a crash #534

Open
albertmoravec opened this issue Dec 19, 2024 · 1 comment · May be fixed by #535
Open

[BUG] updateMyLocationEnabled() call on style load causes a crash #534

albertmoravec opened this issue Dec 19, 2024 · 1 comment · May be fixed by #535
Labels
bug Something isn't working

Comments

@albertmoravec
Copy link

Platforms

android

Version of flutter maplibre_gl

0.20.0

Bug Description

In specific cases that I'm yet to determine the call to updateMyLocationEnabled() in onStyleLoadedCallback causes an app crash due to unhandled LocationComponentNotInitializedException.

Here's a stack trace of such crash:

E/Mbgl-MapChangeReceiver(12675): Exception in onDidFinishLoadingStyle
E/Mbgl-MapChangeReceiver(12675): org.maplibre.android.location.LocationComponentNotInitializedException: The LocationComponent has to be activated with one of the LocationComponent#activateLocationComponent overloads before any other methods are invoked.
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.location.LocationComponent.checkActivationState(LocationComponent.java:1557)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.location.LocationComponent.getLocationEngine(LocationComponent.java:905)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.maplibregl.MapLibreMapController.startListeningForLocationUpdates(MapLibreMapController.java:2036)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.maplibregl.MapLibreMapController.updateMyLocationEnabled(MapLibreMapController.java:2023)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.maplibregl.MapLibreMapController.access$100(MapLibreMapController.java:98)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.maplibregl.MapLibreMapController$1.onStyleLoaded(MapLibreMapController.java:157)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.maps.MapLibreMap.notifyStyleLoaded(MapLibreMap.java:967)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.maps.MapLibreMap.onFinishLoadingStyle(MapLibreMap.java:229)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1348)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
E/Mbgl-MapChangeReceiver(12675):   at org.maplibre.android.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1129)
E/Mbgl-MapChangeReceiver(12675):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/Mbgl-MapChangeReceiver(12675):   at android.os.MessageQueue.next(MessageQueue.java:335)
E/Mbgl-MapChangeReceiver(12675):   at android.os.Looper.loop(Looper.java:193)
E/Mbgl-MapChangeReceiver(12675):   at android.app.ActivityThread.main(ActivityThread.java:8061)
E/Mbgl-MapChangeReceiver(12675):   at java.lang.reflect.Method.invoke(Native Method)
E/Mbgl-MapChangeReceiver(12675):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/Mbgl-MapChangeReceiver(12675):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/System.err(12675): org.maplibre.android.location.LocationComponentNotInitializedException: The LocationComponent has to be activated with one of the LocationComponent#activateLocationComponent overloads before any other methods are invoked.
W/System.err(12675):   at org.maplibre.android.location.LocationComponent.checkActivationState(LocationComponent.java:1557)
W/System.err(12675):   at org.maplibre.android.location.LocationComponent.getLocationEngine(LocationComponent.java:905)
W/System.err(12675):   at org.maplibre.maplibregl.MapLibreMapController.startListeningForLocationUpdates(MapLibreMapController.java:2036)
W/System.err(12675):   at org.maplibre.maplibregl.MapLibreMapController.updateMyLocationEnabled(MapLibreMapController.java:2023)
W/System.err(12675):   at org.maplibre.maplibregl.MapLibreMapController.access$100(MapLibreMapController.java:98)
W/System.err(12675):   at org.maplibre.maplibregl.MapLibreMapController$1.onStyleLoaded(MapLibreMapController.java:157)
W/System.err(12675):   at org.maplibre.android.maps.MapLibreMap.notifyStyleLoaded(MapLibreMap.java:967)
W/System.err(12675):   at org.maplibre.android.maps.MapLibreMap.onFinishLoadingStyle(MapLibreMap.java:229)
W/System.err(12675):   at org.maplibre.android.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1348)
W/System.err(12675):   at org.maplibre.android.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
W/System.err(12675):   at org.maplibre.android.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1129)
W/System.err(12675):   at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(12675):   at android.os.MessageQueue.next(MessageQueue.java:335)
W/System.err(12675):   at android.os.Looper.loop(Looper.java:193)
W/System.err(12675):   at android.app.ActivityThread.main(ActivityThread.java:8061)
W/System.err(12675):   at java.lang.reflect.Method.invoke(Native Method)
W/System.err(12675):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
W/System.err(12675):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
E/libc++abi(12675): terminating with uncaught exception of type jni::PendingJavaException
F/libc    (12675): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 12675 (netag.app.debug), pid 12675 (netag.app.debug)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/raphael_eea/raphael:11/RKQ1.200826.002/V12.5.1.0.RFKEUXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2024-12-17 12:38:41+0100
pid: 12675, tid: 12675, name: netag.app.debug  >>> cz.dronetag.app.debug <<<
uid: 10522
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'terminating with uncaught exception of type jni::PendingJavaException'
    x0  0000000000000000  x1  0000000000003183  x2  0000000000000006  x3  0000007fd9df3320
    x4  fefeff6d6e68736f  x5  fefeff6d6e68736f  x6  fefeff6d6e68736f  x7  7f7f7f7f7f7f7f7f
    x8  00000000000000f0  x9  90c8ee19c44b1960  x10 0000000000000000  x11 ffffffc0fffffbdf
    x12 0000000000000001  x13 00000000676162c1  x14 001aa6e81584387f  x15 0000b7ee629427fb
    x16 00000073b8694948  x17 00000073b8671490  x18 00000073bc1ec000  x19 0000000000003183
    x20 0000000000003183  x21 00000000ffffffff  x22 0000007fd9df3450  x23 0000007fd9df3490
    x24 0000007fd9df3570  x25 0000007fd9df34b8  x26 b4000072c8ac6390  x27 0000000000000001
    x28 0000000000000001  x29 0000007fd9df33a0
    lr  00000073b8620cf8  sp  0000007fd9df3300  pc  00000073b8620d24  pst 0000000000000000
backtrace:
      #00 pc 000000000008cd24  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: d2bad1502ac7810a2cce958ef2191244)
      #01 pc 00000000009bf998  /data/app/~~U4fojBjmt6oct55I3Ik59g==/cz.dronetag.app.debug-k0STtUw_oIk8hrtwhfRtsw==/base.apk!libmaplibre.so (offset 0x3db2000) (BuildId: 545887988105fea909ce11acfe599ad1e7db51a4)

Steps to Reproduce

I'm unsure about the absolute root cause, but this bug started happening when I wired myLocationEnabled to location availability stream. It's likely that there is a race condition with myLocationEnabled value being changed before map view initialization is finished.

You can see an example of the setup in the code sample below.

Expected Results

Location manager is initialized without a crash.

Actual Results

Location manager initialization fails and causes an app crash.

Code Sample

StreamBuilder<bool>(
    stream: locationAvailableStream, // Stream<bool>
    initialData: false,
    builder: (context, snapshot) => MapLibreMap(
        myLocationEnabled: snapshot.data ?? false,
        // ...
    ),
);
@albertmoravec albertmoravec added the bug Something isn't working label Dec 19, 2024
@albertmoravec
Copy link
Author

Received maybe a bit better stack trace:

E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): Failed to handle method call
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): java.lang.NullPointerException: Style in LocationComponentActivationOptions is null. Make sure the Style object isn't null. Wait for the map to fully load before passing the Style object to LocationComponentActivationOptions.
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.android.location.LocationComponentActivationOptions$Builder.build(LocationComponentActivationOptions.java:292)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.maplibregl.MapLibreMapController.enableLocationComponent(MapLibreMapController.java:296)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.maplibregl.MapLibreMapController.updateMyLocationEnabled(MapLibreMapController.java:2019)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.maplibregl.MapLibreMapController.setMyLocationEnabled(MapLibreMapController.java:1907)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.maplibregl.Convert.interpretMapLibreMapOptions(Convert.java:253)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at org.maplibre.maplibregl.MapLibreMapController.onMethodCall(MapLibreMapController.java:688)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at android.os.Looper.loop(Looper.java:236)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at android.app.ActivityThread.main(ActivityThread.java:8061)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/MethodChannel#plugins.flutter.io/maplibre_gl_0(30248): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/Mbgl    (30248): {netag.app.debug}[ParseStyle]: source must have tiles
E/Mbgl-MapChangeReceiver(30248): Exception in onDidFinishLoadingStyle
E/Mbgl-MapChangeReceiver(30248): org.maplibre.android.location.LocationComponentNotInitializedException: The LocationComponent has to be activated with one of the LocationComponent#activateLocationComponent overloads before any other methods are invoked.
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.location.LocationComponent.checkActivationState(LocationComponent.java:1557)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.location.LocationComponent.getLocationEngine(LocationComponent.java:905)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.maplibregl.MapLibreMapController.startListeningForLocationUpdates(MapLibreMapController.java:2036)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.maplibregl.MapLibreMapController.updateMyLocationEnabled(MapLibreMapController.java:2023)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.maplibregl.MapLibreMapController.access$100(MapLibreMapController.java:98)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.maplibregl.MapLibreMapController$1.onStyleLoaded(MapLibreMapController.java:157)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.maps.MapLibreMap.notifyStyleLoaded(MapLibreMap.java:967)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.maps.MapLibreMap.onFinishLoadingStyle(MapLibreMap.java:229)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1348)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
E/Mbgl-MapChangeReceiver(30248): 	at org.maplibre.android.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1129)
E/Mbgl-MapChangeReceiver(30248): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/Mbgl-MapChangeReceiver(30248): 	at android.os.MessageQueue.next(MessageQueue.java:335)
E/Mbgl-MapChangeReceiver(30248): 	at android.os.Looper.loop(Looper.java:193)
E/Mbgl-MapChangeReceiver(30248): 	at android.app.ActivityThread.main(ActivityThread.java:8061)
E/Mbgl-MapChangeReceiver(30248): 	at java.lang.reflect.Method.invoke(Native Method)
E/Mbgl-MapChangeReceiver(30248): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/Mbgl-MapChangeReceiver(30248): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/System.err(30248): org.maplibre.android.location.LocationComponentNotInitializedException: The LocationComponent has to be activated with one of the LocationComponent#activateLocationComponent overloads before any other methods are invoked.
W/System.err(30248): 	at org.maplibre.android.location.LocationComponent.checkActivationState(LocationComponent.java:1557)
W/System.err(30248): 	at org.maplibre.android.location.LocationComponent.getLocationEngine(LocationComponent.java:905)
W/System.err(30248): 	at org.maplibre.maplibregl.MapLibreMapController.startListeningForLocationUpdates(MapLibreMapController.java:2036)
W/System.err(30248): 	at org.maplibre.maplibregl.MapLibreMapController.updateMyLocationEnabled(MapLibreMapController.java:2023)
W/System.err(30248): 	at org.maplibre.maplibregl.MapLibreMapController.access$100(MapLibreMapController.java:98)
W/System.err(30248): 	at org.maplibre.maplibregl.MapLibreMapController$1.onStyleLoaded(MapLibreMapController.java:157)
W/System.err(30248): 	at org.maplibre.android.maps.MapLibreMap.notifyStyleLoaded(MapLibreMap.java:967)
W/System.err(30248): 	at org.maplibre.android.maps.MapLibreMap.onFinishLoadingStyle(MapLibreMap.java:229)
W/System.err(30248): 	at org.maplibre.android.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1348)
W/System.err(30248): 	at org.maplibre.android.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
W/System.err(30248): 	at org.maplibre.android.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1129)
W/System.err(30248): 	at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(30248): 	at android.os.MessageQueue.next(MessageQueue.java:335)
W/System.err(30248): 	at android.os.Looper.loop(Looper.java:193)
W/System.err(30248): 	at android.app.ActivityThread.main(ActivityThread.java:8061)
W/System.err(30248): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err(30248): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
W/System.err(30248): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
E/libc++abi(30248): terminating with uncaught exception of type jni::PendingJavaException
F/libc    (30248): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 30248 (netag.app.debug), pid 30248 (netag.app.debug)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/raphael_eea/raphael:11/RKQ1.200826.002/V12.5.1.0.RFKEUXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2024-12-19 13:43:17+0100
pid: 30248, tid: 30248, name: netag.app.debug  >>> cz.dronetag.app.debug <<<
uid: 10522
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'terminating with uncaught exception of type jni::PendingJavaException'
    x0  0000000000000000  x1  0000000000007628  x2  0000000000000006  x3  0000007fd9df3320
    x4  fefeff6d6e68736f  x5  fefeff6d6e68736f  x6  fefeff6d6e68736f  x7  7f7f7f7f7f7f7f7f
    x8  00000000000000f0  x9  90c8ee19c44b1960  x10 0000000000000000  x11 ffffffc0fffffbdf
    x12 0000000000000001  x13 00000000676414e5  x14 000d79bf2ffe0828  x15 0000c4937c7ebdee
    x16 00000073b8694948  x17 00000073b8671490  x18 00000073bc1ec000  x19 0000000000007628
    x20 0000000000007628  x21 00000000ffffffff  x22 0000007fd9df3450  x23 0000007fd9df3490
    x24 0000007fd9df3570  x25 0000007fd9df34b8  x26 b40000727f8b8e60  x27 0000000000000001
    x28 0000000000000001  x29 0000007fd9df33a0
    lr  00000073b8620cf8  sp  0000007fd9df3300  pc  00000073b8620d24  pst 0000000000000000
backtrace:
      #00 pc 000000000008cd24  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: d2bad1502ac7810a2cce958ef2191244)
      #01 pc 00000000009bf998  /data/app/~~j7BnA03KWZMwNVFTctWcSQ==/cz.dronetag.app.debug-L5iI8FLTggrWjdpfqrrQEw==/base.apk!libmaplibre.so (offset 0x3db0000) (BuildId: 545887988105fea909ce11acfe599ad1e7db51a4)
Lost connection to device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant