mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

Add layer failed: bad_variant_access

Open Ashok-Media opened this issue 1 year ago • 3 comments

Environment

  • Android OS version: Android 12
  • Devices affected: Galaxy A12
  • Maps SDK Version: 11.0.0

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

Ashok-Media avatar Apr 12 '24 08:04 Ashok-Media

@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.

kiryldz avatar Apr 12 '24 08:04 kiryldz

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), ) } } }

Ashok-Media avatar Apr 12 '24 09:04 Ashok-Media

@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.

kiryldz avatar Apr 12 '24 10:04 kiryldz