mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
430 stars 126 forks source link

Add layer failed: bad_variant_access #2342

Open Ashok-Media opened 1 month ago

Ashok-Media commented 1 month ago

Environment

Observed behavior and steps to reproduce

Not able to reproduce this crash however happening in live for few users

Fatal Exception: com.mapbox.maps.MapboxStyleException: Add layer failed: bad_variant_access at com.mapbox.maps.extension.style.layers.Layer.bindTo(Layer.java:154) at com.mapbox.maps.extension.style.layers.LayerUtils.addLayerBelow(:16) at com.launcher.android.radarhome.presentation.ui.radar.ui.RadarFragment$initObservers$5.invoke$lambda$6$lambda$5(RadarFragment.java:219) at com.mapbox.maps.StyleObserver.run(:36) at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:186) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8663) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Expected behavior

It should not crash

kiryldz commented 1 month ago

@Ashok-Media without context it's rather hard to say when this could happen. If you will not be able to provide more context when exactly this might happen in your app (e.g. on style change, app went to background) I would suggest you:

  1. Try update to later version (v11.3.0).
  2. If crash is still there - simply catch our dedicated MapboxStyleException in your code and, perhaps, gather more data that you could share with us so that this issue becomes actionable from our end.

Closing this for now, feel free to re-open if you would have more data.

Ashok-Media commented 1 month ago

as per the log this crash is occur inside the loadstyle(style) block mapboxMap?.loadStyle(currentStyle) { style -> if (style.isValid()) { rasterLayers?.forEach { rasterLayer: RasterLayer -> style.addLayerBelow( rasterLayer, RadarUtils.getLayerId(radarViewModel.mapStyleChangeLiveData.value), ) } } }

kiryldz commented 1 month ago

@Ashok-Media please do not open new issues duplicating existing ones. Thanks for the code, sadly it's not enough to say why it could lead to a crash, generally looks valid (and as you said, it crashes for few users only). I'll leave this issue open until more information will be provided.